Skip to main content

Player

API for interacting with players.

Functions

Player.getConnecting

Returns a list of players who are currently connecting, but are not yet connected. See the "connecting" event for more details.

Player.getConnecting(): Player[]

Returns

NameTypeDescription
playersPlayer[]Connecting players

Player.getConnected

Returns a list of players who are currently connected. See the "connected" event for more details.

Player.getConnected(): Player[]

Returns

NameTypeDescription
playersPlayer[]Connected players

Player.isConnecting

Returns whether the given player is currently connecting, but not yet connected. See the "connecting" event for more details.

Player.isConnecting(player: Player): boolean

Parameters

NameTypeDescription
playerPlayerPlayer to check.

Returns

NameTypeDescription
isConnectingbooleanTrue if the player is connecting.

Player.isConnected

Returns whether the given player is currently connected. See the "connected" event for more details.

Player.isConnected(player: Player): boolean

Parameters

NameTypeDescription
playerPlayerPlayer to check.

Returns

NameTypeDescription
isConnectedbooleanTrue if the player is connected.

Player.getEntity

Returns the replicated entity representing this player, or nil if not yet initialised.

You should use this for replicating information about the player (e.g. position) across the network. Note that unlike regular entities, when the player entity is deleted it does not delete its children. You must clean up any child entities on disconnect by hand.

Player.getEntity(player: Player): entity?

Parameters

NameTypeDescription
playerPlayerPlayer to get the entity of.

Returns

NameTypeDescription
entityentity?The player's entity or nil.

Player.getId

Returns the unique ID for this player (their SteamID 64 on Steamworks-enabled builds of TASBox).

You should use this when determining if two players are the same, as the player userdata objects passed to the scripting environment are always a new instance (and thus won't be equal).

Player.getId(player: Player): string

Parameters

NameTypeDescription
playerPlayerPlayer to get the ID of.

Returns

NameTypeDescription
idstringUnique ID of the player.

Player.getLocalPlayer

Gets the local player.

Player.getLocalPlayer(): Player

Returns

NameTypeDescription
playerPlayerInstance of the local player.

Player.isLocalPlayer

Returns whether the given player is the local player.

Player.isLocalPlayer(player: Player): boolean

Parameters

NameTypeDescription
playerPlayerPlayer to check.

Returns

NameTypeDescription
isLocalPlayerbooleanTrue if the player is the local player.

Player.kick

Kicks the player from the server if they were connecting or connected.

Player.kick(player: Player)

Parameters

NameTypeDescription
playerPlayerPlayer to kick.

Player.addEventListener

Adds an event listener. A list of events can be found here.

Player.addEventListener(eventType: string, callback: function): function

Parameters

NameTypeDescription
eventTypestringThe event to listen for.
callbackfunctionThe callback to use.

Returns

NameTypeDescription
callbackfunctionThe callback that was registered.

Player.removeEventListener

Removes an event listener.

Player.removeEventListener(eventType: string, callback: function)

Parameters

NameTypeDescription
eventTypestringThe event to remove the listener from.
callbackfunctionThe callback to remove.

Enums

DisconnectReason

Why the player was disconnected.

Value
PlayerDisconnected
PlayerKicked
ServerClosed
ServerRejected
ServerFull
ConnectionFailed
InternalError

Events

"connecting"

Fired when a player first starts connecting to the server, but before they've authenticated.

Player.addEventListener("connecting", fn(player) end)

Parameters

NameTypeDescription
playerPlayerThe player who started connecting.

"connected"

Fired when a player finishes connecting to the server, after they've successfully authenticated.

Player.addEventListener("connected", fn(player) end)

Parameters

NameTypeDescription
playerPlayerThe player who finished connecting.

"disconnected"

Fired when a player disconnects - or is disconnected from - the server.

This includes players who started connecting but didn't finish. Don't assume you previously received a "connected" event for a player when you receive a "disconnected" event for that player!

Player.addEventListener("disconnected", fn(player, reason) end)

Parameters

NameTypeDescription
playerPlayerThe player who disconnected.
reasonPlayer.DisconnectReasonWhy they were disconnected.