Player
Represents a connected client. Exposes account data, health, team membership, inventory and chat events.
Player objects are returned by Players and passed to events such as PlayerAdded and Touched.
Properties
Name
player.Name: stringAccount username. Read only.
UserId
player.UserId: numberNumeric account id. Stable across sessions. Read only.
Role
player.Role: stringPlatform role, for example user, moderator or admin. Read only.
Rank
player.Rank: stringRank within this game, for example Owner or Visitor. Read only.
Character
player.Character: CharacterThe player's in-world Character.
Health
player.Health: numberCurrent health. Writable.
Team
player.Team: Team?Current team, or nil. Assign to change team.
EquippedTool
player.EquippedTool: Tool?Currently equipped tool, or nil. Read only.
Methods
SetStat
player:SetStat(name: string, value: any)Sets a leaderboard stat. Maximum 4 stats per player.
player:SetStat("Coins", 10)SendMessage
player:SendMessage(text: string)Sends a system chat message visible only to this player.
TakeDamage
player:TakeDamage(amount: number, attacker: Player?): booleanApplies damage. attacker is used for friendly-fire checks and kill attribution. Returns true if damage was applied.
Teleport
player:Teleport(position: Vector3)Teleports the character to position.
Respawn
player:Respawn()Respawns the character at a spawn location.
Kick
player:Kick(reason: string?)Disconnects the player from the server. reason is shown to the player.
SetTeam
player:SetTeam(team: Team?)Equivalent to assigning Team.
GetTeam
player:GetTeam(): Team?Equivalent to reading Team.
GiveTool
player:GiveTool(tool: Tool): booleanAdds a tool to the player's inventory. Returns true on success. Inventory limit is 16 tools.
TakeTool
player:TakeTool(tool: Tool): booleanRemoves a tool from the player's inventory. Returns true on success.
HasTool
player:HasTool(tool: Tool): booleanReturns true if the tool is in the player's inventory.
GetTools
player:GetTools(): { Tool }Returns the tools in the player's inventory.
Events
CharacterAdded
player.CharacterAdded(character: Character)Fires when the player's character spawns or respawns.
Died
player.Died(killer: Player?)Fires when the player dies. killer is the attributed player, or nil.
player.Died:Connect(function(killer)
if killer then
killer:SendMessage("You knocked out " .. player.Name)
end
end)TeamChanged
player.TeamChanged(newTeam: Team?, oldTeam: Team?)Fires when the player's team changes.
Chatted
player.Chatted(text: string)Fires when the player sends a chat message.