Session
tracks the players on this server, the character each one drives, and the signals that fire as they join, leave, and die
Properties
3 members Access: read only
- CharacterDied:
Signal fires with the character, the user id, and the attacker
- PlayerJoined:
Signal fires when a player joins
- PlayerLeft:
Signal fires when a player leaves
Methods
4 members
- BindCharacter
(userId: number, character: Instance) -> ()[server] bind a character entity to a user
Parameters
Name Type Description userId number Player user ID to associate. character Instance Character entity to bind to the player. returns () — - CharacterOf
(userId: number) -> Instance? the character bound to a user
Parameters
Name Type Description userId number Player user ID whose character to look up. returns Instance? — - Kick
(userId: number, reason: string?) -> boolean[server] remove a player from this server
Parameters
Name Type Description userId number Player user ID to disconnect. reason string? Optional explanation displayed to the disconnected player. returns boolean — - LocalCharacter
() -> Instance? the character entity of the local client
Managing Player Connections and Avatars
Lifecycle: Server
Joins and leaves are the two hooks a character spawn cycle hangs off.
Luau
local function spawnCharacter(userId: number) local character = game.Prefabs.Spawn("Cadet") if character then character.Position = Vector3.new(0, 5, 0) game.Session.BindCharacter(userId, character) endendgame.Session.PlayerJoined:Connect(function(userId: number) print("Player joined:", userId) spawnCharacter(userId)end)game.Session.PlayerLeft:Connect(function(character, userId: number) print("Player left:", userId) if character then character:Destroy() endend)