Players
Everyone in the game: one Player object per connected person.
- Inherits: Service → Instance
- Creatable: No. It’s created with the game; use
Players(import { Players } from '@rally/sdk'). - Replication: Replicated: clients get a copy, and changes the server makes reach them.
The server adds a Player when someone joins and removes it when they leave; players’ devices see the same list through replication.
Properties
Section titled “Properties”maxPlayers
Section titled “maxPlayers”Type: number · Default: 20 · Access: read-only · Replicates: yes
The most players one game server holds, from the game’s settings (1 to 100). When every server of the game is full, Rally starts another one for new players.
characterAutoLoads
Section titled “characterAutoLoads”Type: boolean · Default: true · Access: read/write · Replicates: yes
Spawn characters automatically on join and after death.
When off, characters don’t spawn on their own: call player.loadCharacter().
respawnTime
Section titled “respawnTime”Type: number · Default: 3 · Range: 0 to 60 (clamped) · Access: read/write · Replicates: yes
Seconds between death and respawn.
Only used when characterAutoLoads is on.
localPlayer
Section titled “localPlayer”Type: Player | null · Access: read-only
Client: you. Server: null.
It’s set before LocalScripts start.
Inherited from Instance: name, archivable, id, className, parent, destroyed
Methods
Section titled “Methods”getPlayers
Section titled “getPlayers”getPlayers(): Player[]Everyone in the game right now.
getPlayerByUserId
Section titled “getPlayerByUserId”getPlayerByUserId(userId: string): Player | undefinedThe player with this Rally account id, or undefined.
getPlayerFromCharacter
Section titled “getPlayerFromCharacter”getPlayerFromCharacter(inst: Instance): Player | undefinedThe player whose character this is (or which contains this part).
Pass what a touched handler receives to find out which player touched a part. Returns
undefined for anything that isn’t (inside) a player’s character.
Inherited from Instance: getPropertyChangedSignal, setAttribute, getAttribute, getAttributes, getAttributeChangedSignal, getChildren, getDescendants, findFirstChild, findFirstChildOfClass, findFirstChildWhichIsA, findFirstAncestor, findFirstAncestorWhichIsA, waitForChild, isA, isDescendantOf, isAncestorOf, getFullName, clearAllChildren, destroy, clone, toString
Events
Section titled “Events”playerAdded
Section titled “playerAdded”Arguments: player: Player
Fires when someone joins. On the server it fires after their Player and PlayerGui exist and before
their character spawns. On a player’s device it fires as Player objects arrive: players who were
already there when the LocalScript started don’t fire it, so check getPlayers() too.
playerRemoving
Section titled “playerRemoving”Arguments: player: Player
Fires when someone leaves, before their Player is removed. Save their data here.
Inherited from Instance: changed, childAdded, childRemoved, descendantAdded, descendantRemoving, ancestryChanged, destroying, attributeChanged
Examples
Section titled “Examples”Leaderstats that are saved
Section titled “Leaderstats that are saved”import { DataStoreService, NumberValue, Players, createLeaderstats, task, warn } from '@rally/sdk';
const coinsStore = DataStoreService.getDataStore('Coins');
Players.playerAdded.connect((player) => { const stats = createLeaderstats(player, { Coins: 0 }); task.spawn(async () => { stats.Coins.value = (await coinsStore.get<number>(player.userId)) ?? 0; });});
Players.playerRemoving.connect((player) => { const coins = player.findFirstChild('leaderstats')?.findFirstChild('Coins'); if (!(coins instanceof NumberValue)) return; task.spawn(async () => { try { await coinsStore.set(player.userId, coins.value); } catch (e) { warn('saving coins failed', e); } });});