# onPlayerConnect (Server)

> Fired when a connection is about to be admitted, before the player exists. Cancelling the event refuses it.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Event
- **Side**: Server
- **Category**: Players and accounts
- **Cancellable**: `cancelEvent`
- **URL**: https://wiki.mymp.gg/en/onPlayerConnect

## Syntax

```lua
addEventHandler("onPlayerConnect", root, function(string playerName) ... end)
```

## Handler parameters

| Name | Type | Description |
| --- | --- | --- |
| `playerName` | `string` | The name the player will join under: the account's `Name#Tag` on a server with a `server_key`, otherwise the name they brought. |

## Source

The root element (`root`). The player does not exist yet.

## Example

```lua
local banned = { ["Griefer#0001"] = true }

addEventHandler("onPlayerConnect", root, function(playerName)
    if banned[playerName] then
        cancelEvent()
    end
end)
```

## See also

- [onPlayerJoin (Server)](https://wiki.mymp.gg/en/onPlayerJoin.md): Fired when a player has finished joining and has received the server's initial state.
- [onPlayerQueue (Server)](https://wiki.mymp.gg/en/onPlayerQueue.md): Fired when an account is about to join the queue of a full server. Cancelling the event refuses it.
- [kickPlayer (Server)](https://wiki.mymp.gg/en/kickPlayer.md): Disconnects a player from the server with a reason.
