Skip to main content
Server events allow you to monitor and control player connections to backend servers, handle server switching, manage kicks, and respond to server registration changes.

Server Selection Events

PlayerChooseInitialServerEvent

Fired when a player has finished the login process and the proxy needs to choose the first server to connect to. The proxy will wait on this event before initiating the connection.
Example: Custom Initial Server Logic

ServerPreConnectEvent

Fired before a player connects to a server. You can modify the target server or cancel the connection.
Example: Access Control and Load Balancing

Server Connection Events

ServerConnectedEvent

Fired before the player completely transitions to the target server and the connection to the previous server has been de-established. Use Server() to get the target server since Player.CurrentServer() is not yet updated.
Example: Track Server Switches

ServerPostConnectEvent

Fired after the player has fully connected to a server. The server the player is now connected to is available via Player().CurrentServer().
Example: Send Server-Specific Messages

Kick and Disconnect Events

KickedFromServerEvent

Fired when a player is kicked from a server. You can either allow the proxy to kick the player, redirect them to another server, or just notify them.
ServerKickResult types:
Example: Fallback Server on Kick

Server Transfer Events

PreTransferEvent

Fired before a player is transferred to another host, either by the backend server or by a plugin using Player.TransferTo().
Example: Control Player Transfers

Server Registration Events

ServerRegisteredEvent

Fired when a backend server is registered with the proxy. This allows plugins to react to dynamically added servers.
Example: Initialize Server Resources

ServerUnregisteredEvent

Fired when a backend server is unregistered from the proxy. This allows plugins to perform necessary cleanup.
Example: Cleanup Server Resources

Complete Server Management Example

Here’s a comprehensive example showing how to build a load balancer with automatic failover:

Best Practices

1. Always Check for Nil

Many server-related events have fields that may be nil:

2. Use ServerInfoEqual for Comparison

3. Handle Connection Failures

4. Log Server Events

Always log server-related events for debugging and monitoring:

See Also