Players
Contains connected Player instances and manages player lifecycle events.
- Service
game:GetService("Players")- Inherits
- Instance
- Replication
- Never
Behavior
Players contains the Player instances for connected players.
Use its events to track joins and departures, and GetPlayers to query players
already connected.
Summary
The player associated with this client.
The maximum number of players accepted by the server.
The current number of connected players.
Whether characters respawn automatically or require a script to load them.
The delay between character death and respawn, in seconds.
Displays a chat message associated with the supplied Part or character.
Creates the local Player used by a standalone or test session.
Returns this instance if it is an ExecutionGroup.
Returns the connected Player with the specified user identifier, or nil if none exists.
Returns the player whose Character matches the supplied model, or nil if no player matches.
Returns a snapshot array of connected players.
Respawns the specified player immediately without waiting for RespawnTime.
Sends a message to the player's team chat.
Fires when a player joins.
Fires before a player is removed.
Properties
LocalPlayer
Players.LocalPlayer: Player = nilThe player associated with this client. Returns nil on the server.
MaxPlayers
Players.MaxPlayers: number = 50The maximum number of players accepted by the server.
NumPlayers
Players.NumPlayers: numberThe current number of connected players.
RespawnPolicy
Players.RespawnPolicy: Enum.RespawnPolicy = Enum.RespawnPolicy.AutomaticWhether characters respawn automatically or require a script to load them.
RespawnTime
Players.RespawnTime: number = 5The delay between character death and respawn, in seconds. Set to 0 for immediate respawn.
Methods
Chat
Players:Chat(message: string): ()Displays a chat message associated with the supplied Part or character.
CreateLocalPlayer
Players:CreateLocalPlayer(userId: number, name: string): PlayerCreates the local Player used by a standalone or test session.
GetExecutionGroup
Players:GetExecutionGroup(): ExecutionGroup?Returns this instance if it is an ExecutionGroup. Otherwise returns the nearest ancestor ExecutionGroup, or nil when no group contains the instance.
GetPlayerByUserId
Players:GetPlayerByUserId(userId: number): Player?Returns the connected Player with the specified user identifier, or nil if none exists.
GetPlayerFromCharacter
Returns the player whose Character matches the supplied model, or nil if no player matches.
GetPlayers
Players:GetPlayers(): tableReturns a snapshot array of connected players.
RespawnPlayer
Players:RespawnPlayer(player: Player): booleanRespawns the specified player immediately without waiting for RespawnTime.
TeamChat
Players:TeamChat(message: string): ()Sends a message to the player's team chat.
Events
PlayerAdded
Players.PlayerAdded: RBXScriptSignalFires when a player joins. Passes the Player. Existing players do not trigger this event when a connection is added. Connect before querying GetPlayers, and make initialization safe to repeat.
PlayerRemoving
Players.PlayerRemoving: RBXScriptSignalFires before a player is removed. Passes the departing Player. Read or save required session state before removal.
Inherited members
- Properties
- ArchivableClassNameNameParent
- Methods
- AddComponent()AddTag()ClearAllChildren()ClearTags()Clone()Destroy()FindFirstAncestor()FindFirstAncestorOfClass()FindFirstAncestorWhichIsA()FindFirstChild()FindFirstChildOfClass()FindFirstChildWhichIsA()FindFirstDescendant()GetAttribute()GetAttributeChangedSignal()GetAttributes()GetChildren()GetComponent()GetComponentChangedSignal()GetComponents()GetDebugId()GetDescendants()GetFullName()GetPropertyChangedSignal()GetReferencing()GetTags()HasComponent()HasTag()IsA()IsAncestorOf()IsDescendantOf()RemoveComponent()RemoveTag()SetAttribute()WaitForChild()
- Events
- AncestryChangedAttributeChangedChangedChildAddedChildRemovedDescendantAddedDescendantRemovingDestroying
Example
local Players = game:GetService("Players")
for _, player in Players:GetPlayers() do
print(player.UserId)
end