Skip to content
Untitled Sandbox - Developer Documentation
docs/api/players

@usbx/players

Joins, leaves, spawns and deaths

local players = require("@usbx/players")

players.joined

event

Fires when a player joins.

players.joined: Event<(Player)>
example
players.joined:connect(function(player) print(player.name) end)

Use it forgreeting new players, or handing out starting items the moment they arrive.

players.left

event

Fires when a player leaves.

players.left: Event<(Player)>
example
players.left:connect(function(player) print("player", player.id, "left") end)

Use it forsaving a player's progress, or cleaning up the things they left behind.

players.spawned

event

Fires when a player spawns, also after each respawn.

players.spawned: Event<(Player)>
example
players.spawned:connect(function(player) player.walk_speed = 20 end)

Use it forhanding out gear or setting a player's speed every time they spawn or respawn.

players.died

event

Fires when a player dies. It does not say who did it: keep the by of Player:damage for that.

players.died: Event<(Player)>
example
players.died:connect(function(player) print(player.name, "died") end)

Use it forcounting deaths, ending a round, or dropping loot where a player fell.

players.chatted

event

Fires when a player sends a chat message, with the player and the text.

players.chatted: Event<(Player, string)>
example
players.chatted:connect(function(player, message) print(player.name, message) end)

Use it forchat commands, secret passwords, or word guessing games that read what players type.

players.all

function

Every connected player.

players.all() -> { Player }
example
for _, player in players.all() do print(player.name) end

Use it forrewarding everyone, teleporting the whole server, or starting a round for all players.

players.get

function

Finds a connected player by their id in this server, or gives nil. Ids count up, so the id of a player who left does not find a newer player.

players.get(id: number) -> Player?
example
local player = players.get(1)

Use it forlooking up a player again from an id you saved earlier, as long as they are still in the server.

idThe player's id in this server, Player.id.

players.respawn_time

value

Seconds from a death to the respawn, 1.1 by default, or "never" to keep dead players dead until a script spawns them. Writable.

players.respawn_time: number | "never"

Use it forelimination rounds, where dead players stay out and wait until the next round starts.

players.set_spawns_enabled

function

Turns spawn points on or off: those with the tag, those of the team, or all of them.

players.set_spawns_enabled(enabled: boolean, filter: { … }?) -> ()
example
players.set_spawns_enabled(false, { tag = "Lobby" })

Use it forswitching between lobby spawns and arena spawns as your rounds start and end.

enabledTrue turns them on, false turns them off.
filteroptionalWhich spawn points: by tag or by team. Nil means all.
Build a set_spawns_enabled calltag · team
  • tag

    Limits the change to spawn points that have this tag.

  • team

    Limits the change to spawn points of this team, or of the team with this name.

↑ ↓ moveEnter openEsc close