OnPlayerConnect
The handshake is done and the client is loading the level.
The player has a name and an address and no position yet; they are not in the world until OnPlayerSpawn. A returning
player’s record is already readable (GetSavedPlayer). Also called for everyone on the server after a
reload.
Syntax
Section titled “Syntax”function OnPlayerConnect(pid) -- ...end| Parameter | Type | |
|---|---|---|
pid |
number | the player |
Returns
Section titled “Returns”nothing
Example
Section titled “Example”function OnPlayerConnect(pid) local saved = GetSavedPlayer(pid) if saved and saved.visits > 1 then SendClientMessage(pid, COLOUR_SERVER, string.format("Welcome back, %s (visit %d)", GetPlayerName(pid), saved.visits)) else SendClientMessage(pid, COLOUR_SERVER, "Welcome, " .. GetPlayerName(pid) .. ". /help for the commands.") end SendClientMessageToAll(COLOUR_SERVER, GetPlayerName(pid) .. " joined")endSee also
Section titled “See also”OnPlayerRequestSpawn · OnPlayerDisconnect · GetSavedPlayer · the Players group of the index
