---
title: Temporarily Restricting Room Access in Multiplay
slug: world-sdk-guide/temporarily-restricting-room-access-in-multiplay
docTags: 
createdAt: 2024-09-02T08:34:13.135Z
---

You can use the lock, unlock function to restrict or allow room access at your desired timing.

:::hint{type="info"}
**📘&#x20;**&#x50;lease refer to the following guide. \[[ZEPETO.Multiplay(Server) API](https://developer.zepeto.me/docs/multiplay-server/classes/ZEPETO_Multiplay.Sandbox#lock)]
:::

## Lock

The lock function is a function restricts room access.

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



## Unlock

The unlock function is a function that allows room access.
But, if the number of people who are currently connected is the same as the maximum number of people allowed in the room, the room cannot be unlocked.

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



## Example

The following is an example code that uses the lock and unlock functions.

```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"}
## 👍 Difference between lock and private functions

- The locked multiplayer room is not visible in the ZEPETO room list and cannot be entered by invitation.
- Private multiplayer rooms are not shown in the list of ZEPETO rooms, but invitations are acceptable.
:::

