Skip to content

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.

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.

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().

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.

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

getPlayers(): Player[]

Everyone in the game right now.

getPlayerByUserId(userId: string): Player | undefined

The player with this Rally account id, or undefined.

getPlayerFromCharacter(inst: Instance): Player | undefined

The 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

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.

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

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);
}
});
});