---
title: Removing a specific user from Room
slug: world-sdk-guide/removing-a-specific-user-from-room
docTags: 
createdAt: 2024-09-02T08:34:13.135Z
---

You can kick certain users out of the room at runtime.

:::hint{type="danger"}
- Please create the server code index.ts Sandbox.
:::

## Function definition

| kick(client: SandboxPlayer, reason?: string): Promise; | It is a function to kick out the SandboxPlayer after receiving the SandboxPlayer with SessionID.<br /><br />- If you are kicked out, a pop-up will appear informing you that you are kicked out, but the pop-up is the UI of the ZEPETO app and cannot be checked by the editor. |
| ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

:::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#kick)]
:::



First, to get user information, define Schema Types and RoomState as follows:

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-oVK3n8knNlRPitGOhHD1y-20240904-102428.png)

## Example of use

- Use the data in UserInfos to get the session ID of the user who will be kicked out of the userId.
- After importing the sandbox player with the session ID, call the kick function.
- I can tell you who was kicked out through broadcast.

```typescript
import { Sandbox, SandboxOptions, SandboxPlayer } from 'ZEPETO.Multiplay';
import { DataStorage, loadDataStorage } from 'ZEPETO.Multiplay.DataStorage';
import { UserInfo } from 'ZEPETO.Multiplay.Schema';

export default class extends Sandbox {

    onCreate(options: SandboxOptions) {
        this.onMessage("Kick", (client: SandboxPlayer, message: string) => {
            this.tryKick(client, message);
        });
    }

    onJoin(client: SandboxPlayer) {
        const user = new UserInfo();
        user.sessionId = client.sessionId;
        user.userId = client.userId;

        this.state.UserInfos.set(client.userId, user);
    }

    async tryKick(client: SandboxPlayer, userId: string) {
        let player: SandboxPlayer;
        if (userId == null) {
            player = client;
        } else {
            const kickPlayerSessionId: string = this.state.UserInfos.get(userId).sessionId;
            player = this.loadPlayer(kickPlayerSessionId);
        }

        console.log(`try kick : ${player.userId}`);
        await this.kick(player);

        this.broadcast("Log", `kick : ${player.userId}`);
    }
}
```

:::hint{type="success"}
**👍  By default, users who have been kicked out can enter the room again**

- To prevent this, use the DataStorage management function based on the UserId to store the room information that was kicked out by the user.
- You can implement it by calling a kick when you try to enter the room.
:::

