<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [server](./server.md) &gt; [PlayerManager](./server.playermanager.md)

## PlayerManager class

Manages all connected players in a game server.

When to use: accessing online players, reacting to connection lifecycle events, or routing players to worlds. Do NOT use for: constructing or persisting players yourself; players are created automatically on connection.

**Signature:**

```typescript
export default class PlayerManager 
```

## Remarks

Access via `PlayerManager.instance` — do not construct directly.

<h2>Events</h2>

This class emits global events with payloads listed under `PlayerManagerEventPayloads`<!-- -->.

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `PlayerManager` class.

## Example


```typescript
import { PlayerManager } from 'hytopia';

const playerManager = PlayerManager.instance;
const connectedPlayers = playerManager.getConnectedPlayers();
```
\*\*Category:\*\* Players

## Properties

<table><thead><tr><th>

Property


</th><th>

Modifiers


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

[instance](./server.playermanager.instance.md)


</td><td>

`static`

`readonly`


</td><td>

[PlayerManager](./server.playermanager.md)


</td><td>

The global PlayerManager instance (singleton).

\*\*Category:\*\* Players


</td></tr>
<tr><td>

[playerCount](./server.playermanager.playercount.md)


</td><td>

`readonly`


</td><td>

number


</td><td>

The number of players currently connected to the server.

\*\*Category:\*\* Players


</td></tr>
<tr><td>

[worldSelectionHandler?](./server.playermanager.worldselectionhandler.md)


</td><td>


</td><td>

(player: [Player](./server.player.md)<!-- -->) =&gt; Promise&lt;[World](./server.world.md) \| undefined&gt;


</td><td>

_(Optional)_ Optional handler for selecting the world a newly connected player joins.

Use for: lobby routing or game mode selection. Do NOT use for: moving players after they have already joined a world; use `Player.joinWorld`<!-- -->.


</td></tr>
</tbody></table>

## Methods

<table><thead><tr><th>

Method


</th><th>

Modifiers


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

[getConnectedPlayerByUsername(username)](./server.playermanager.getconnectedplayerbyusername.md)


</td><td>


</td><td>

Get a connected player by their username (case-insensitive).


</td></tr>
<tr><td>

[getConnectedPlayers()](./server.playermanager.getconnectedplayers.md)


</td><td>


</td><td>

Get all connected players.


</td></tr>
<tr><td>

[getConnectedPlayersByWorld(world)](./server.playermanager.getconnectedplayersbyworld.md)


</td><td>


</td><td>

Get all connected players in a specific world.


</td></tr>
</tbody></table>
