Players
Inherits from Instance
A service containing currently connected Player objects.
Not Creatable ServiceSummary
Properties
LocalPlayer:PlayerRead OnlyPlayerCollisionEnabled:bool=true
Methods
GetPlayer:PlayerGetPlayerByID:PlayerGetPlayers:array:void
Events
PlayerAdded:voidPlayerRemoved:void
Details
The Players service contains Player objects for all currently connected clients to the game server.
You can use this service to also set the collisions of players using PlayerCollisionEnabled
This service allows you to listen to players joining the game PlayerAdded and players leaving the game PlayerRemoved
Properties
LocalPlayer
Players.LocalPlayer: Player
Returns the local player currently playing.
Example
print(game["Players"].LocalPlayer.Name)
PlayerCollisionEnabled
Players.PlayerCollisionEnabled: bool=true
Determines whether or not collisions between players are enabled.
Example
print("Turning off player collisions!")
game["Players"].PlayerCollisionEnabled = false
Methods
GetPlayer
Players:GetPlayer(username: String): Player
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
username | String | - |
Returns the player instance from their username.
GetPlayerByID
Players:GetPlayerByID(userID: int): Player
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
userID | int | - |
Returns the player instance from their user ID.
GetPlayers:array
Players:GetPlayers:array()
Returns all players in the place as a table.
Example
for i, player in ipairs(game["Players"]:GetPlayers()) do
print(player.Name .." is in the server!")
end
Properties
Events
PlayerAdded
Players.PlayerAdded(player: Player)
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
player | Player | - |
Fires when a player joins the server.
Example
game["Players"].PlayerAdded:Connect(function(player)
if player.Name == "Player" then
player:Kick("A player has joined the server, so they have been removed.")
end
end)
PlayerRemoved
Players.PlayerRemoved(player: Player)
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
player | Player | - |
Fires when a player leaves the server.
Example
game["Players"].PlayerRemoved:Connect(function(player)
if player.Name == "Player" then
print("A player has left the server.")
end
end)