---
title: マルチプレイでの一時的な部屋のアクセス制限
slug: world-sdk-guide-ja/2gcwr4ehcmfc5tUyy9hrp
docTags: 
createdAt: 2024-09-02T08:34:13.135Z
---

ロック、アンロック機能を使用して、希望のタイミングで部屋へのアクセスを制限または許可できます。

:::hint{type="info"}
**📘&#x20;**&#x6B21;のガイドを参照してください。 \[[ZEPETO.Multiplay(Server) API](https://developer.zepeto.me/docs/multiplay-server/classes/ZEPETO_Multiplay.Sandbox#lock)]
:::

## ロック

ロック機能は部屋へのアクセスを制限する機能です。

```typescript
await this.lock();
```



## アンロック

アンロック機能は部屋へのアクセスを許可する機能です。
ただし、現在接続されている人数が部屋に許可されている最大人数と同じ場合、部屋はアンロックできません。

```typescript
await this.unlock();
```



## 例

以下は、ロックとアンロック機能を使用したサンプルコードです。

```typescript
import { Sandbox, SandboxOptions, SandboxPlayer } from 'ZEPETO.Multiplay';

export default class extends Sandbox {

    onCreate(options: SandboxOptions) {

    }

    async onJoin(client: SandboxPlayer) {
        try {
            if (this.clients.length > 8) {
                await this.lock();
            }
        } catch(e) {
            console.error(e);
        }
    }

    async onLeave(client: SandboxPlayer, consented?: boolean){
        try {
            if (this.clients.length <= 8) {
                await this.unlock();
            }
        } catch(e) {
            console.error(e);
        }
    }
}
```

:::hint{type="success"}
## 👍 ロックとプライベート機能の違い

- ロックされたマルチプレイヤールームはZEPETOのルームリストに表示されず、招待によっても入室できません。
- プライベートマルチプレイヤールームはZEPETOのルームリストに表示されませんが、招待は受け付けられます。
:::

