Player

Player : Instance

Overview

Properties

Character

Model

Represents the player's character associated with the player in workspace.

Code Samples

local Players = game:GetService("Players") 

local function OnAddPlayer(player)
    repeat wait(0.1) until player.Character
    local character = player.Character
end
Players.PlayerAdded:Connect(OnAddPlayer)

UserId

string

A unique identifier assigned to the player. This ID can be used for tracking, storing, or identifying the player.

Code Samples

local Players = game:GetService("Players") 

local function OnAddPlayer(player)
    print(player.UserId)
end
Players.PlayerAdded:Connect(OnAddPlayer)

Team

Team

Currently not supported.

Code Samples

TeamColor

BrickColor

Currently not supported.

Code Samples

RespawnLocation

SpawnLocation

Represents the spawn location assigned to the player. This is where the player will respawn upon death.

Code Samples

local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")

local Part = script.Parent
local Checkpoint = Workspace:WaitForChild("Checkpoint")

local function SetCheckpoint(otherPart)
    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChild("Humanoid")
	
    if humanoid then
        local character = humanoid.Parent
        local player = Players:GetPlayerFromCharacter(character)
		
        player.RespawnLocation = Checkpoint
    end
end
Part.Touched:Connect(SetCheckpoint)

Methods

GetMouse

Returns the Mouse object associated with the player. This can be used to detect mouse actions and get the position of the mouse within the game world.

Parameters

Return

Mouse

Code Samples

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()

local function OnButton1Down()
    print("Button1Down", Mouse.Target)
    
    if Mouse.Target.Name == "SpawnLocation" then
        print("Hit SpawnLocation!")
    end
end
Mouse.Button1Down:Connect(OnButton1Down)

LoadCharacter

Load the player avatar character.

Parameters

Return

void

Code Samples

player:LoadCharacter()

RemoveCharacter

Remove the player avatar character that is currently imported.

Parameters

Return

void

Code Samples

player:RemoveCharacter()

Events

CharacterAdded

CharacterAdded is an event that fires when a player's avatar character is added to the game world. This can be used to handle initialization or setup tasks specific to the character, such as configuring its appearance, abilities, or assigning team-based properties.

Parameters

Model Character

Code Samples

local Players = game:GetService("Players") 

local function OnEnterPlayer(player)	
    local function OnCharacterAdded(character)
        print("[OnAddCharacter]", character)	
    end
    player.CharacterAdded:Connect(OnCharacterAdded)	
end
Players.PlayerAdded:Connect(OnEnterPlayer)

CharacterRemoving

CharacterRemoving is an event that fires when a player's avatar character is about to be removed from the game world. This can be used to handle cleanup tasks, save game data, or perform actions such as notifying other parts of the system about the character's removal.

Parameters

Model Character

Code Samples

local Players = game:GetService("Players") 

local function OnEnterPlayer(player)	
    local function OnCharacterRemoving(character)
        print("[OnCharacterRemoving]", character)	
    end
    player.CharacterRemoving:Connect(OnCharacterRemoving)	
end
Players.PlayerAdded:Connect(OnEnterPlayer)

Last updated