Player

Player : Instance

Overview

Player is an instance that encapsulates information about a player who has accessed the world.

Description

The Player class abstracts and manages various details related to the player, including their interactions within the world. It also allows developers to connect event callbacks to handle specific events, such as when a player connects or disconnects from the world. Additionally, each Player instance provides functionality to classify players into groups based on their team color, enabling team-based interactions and management.

Properties

TeamColor

BrickColor

TeamColor is a property representing the team color associated with a player in the game.

Code Samples

//NotWork//

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

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

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)