PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

Players

Show deprecated

Players

Show deprecated

The Players game service contains only Player objects for presently connected clients to a Roblox game server. It also contains information about a place’s configuration (such as bubble chat or classic chat). It can fetch information about players not connected to the server, such as character appearances, friends and avatar thumbnail.

Properties

bool

BubbleChat

[ReadOnly] [NotReplicated]

Indicates whether or not bubble chat is enabled. It is set with the Players/SetChatStyle method.

bool

CharacterAutoLoads

[NotReplicated]

Indicates whether Characters will respawn automatically.

bool

ClassicChat

[ReadOnly] [NotReplicated]

Indicates whether or not classic chat is enabled; set by the Players/SetChatStyle method.

Instance

LocalPlayer

[ReadOnly] [NotReplicated]

The Player that the LocalScript is running for.

int

MaxPlayers

[ReadOnly] [NotReplicated]

The maximum amount of players that can be in this server.

int

MaxPlayersInternal

Players/MaxPlayers for internal use.

int

NumPlayers

[ReadOnly] [NotReplicated] [Deprecated]

Returns the number of people in the server at the current time

int

PreferredPlayers

[ReadOnly] [NotReplicated]

The preferred amount of players for this server.

int

PreferredPlayersInternal

Players/PreferredPlayers for internal use.

float

RespawnTime

Controls the amount of time taken for a players character to respawn

Instance

localPlayer

[Hidden] [ReadOnly] [NotReplicated] [Deprecated]
int

numPlayers

[Hidden] [ReadOnly] [NotReplicated] [Deprecated]

Returns the number of people in the server at the current time

Inherited from Instance: Show Hide

bool

Archivable

Determines if an Instance can be cloned using /Instance/Clone or saved to file.

string

ClassName

[ReadOnly] [NotReplicated]

A read-only string representing the class this Instance belongs to

int

DataCost

[ReadOnly] [NotReplicated] [Deprecated]

The cost of saving the instance using data persistence.

string

Name

A non-unique identifier of the Instance

Instance

Parent

Determines the hierarchical parent of the Instance

bool

RobloxLocked

[Deprecated]

A deprecated property that used to protect CoreGui objects

bool

archivable

[Hidden] [NotReplicated] [Deprecated]
string

className

[ReadOnly] [NotReplicated] [Deprecated]

Functions

void

Chat ( string message )

Makes the local player chat the given message

Instance

CreateHumanoidModelFromDescription ( Instance description , HumanoidRigType rigType )

[Yields]
Instance

CreateHumanoidModelFromUserId ( int64 userId )

[Yields]
Instance

CreateLocalPlayer ( )

Used by the game to create the Player/LocalPlayer

Instance

GetCharacterAppearanceAsync ( int64 userId )

[Yields]

Returns a Model containing the assets which the player is wearing, excluding gear

Dictionary

GetCharacterAppearanceInfoAsync ( int64 userId )

[Yields]

Returns information about the character appearance of a given user

Instance

GetFriendsAsync ( int64 userId )

[Yields]

Returns a FriendPages object which contains information for all of the given player’s friends

Instance

GetHumanoidDescriptionFromOutfitId ( int64 outfitId )

[Yields]
Instance

GetHumanoidDescriptionFromUserId ( int64 userId )

[Yields]
string

GetNameFromUserIdAsync ( int64 userId )

[Yields]

Sends a query to the Roblox website for the username of an account with a given Player/UserId|UserId

Instance

GetPlayerByUserId ( int64 userId )

Returns the Player with the given Player/UserId|UserId if they are in-game

Instance

GetPlayerFromCharacter ( Instance character )

Returns the Player whose Player/Character|Character matches the given instance, or nil if one cannot be found

Objects

GetPlayers ( )

Returns a table of all presently connected Player objects

int64

GetUserIdFromNameAsync ( string userName )

[Yields]

Sends a query to the Roblox website for the Player/UserId|userId of an account with a given username

Tuple

GetUserThumbnailAsync ( int64 userId , ThumbnailType thumbnailType , ThumbnailSize thumbnailSize )

[Yields]

Returns the content URL of a player thumbnail given the size and type (avatar, bust, headshot), and a bool describing if the image is ready to be used

void

ReportAbuse ( Instance player , string reason , string optionalMessage )

Attempts to report the given player for the given reason

void

SetChatStyle ( ChatStyle style )

Sets whether BubbleChat and ClassicChat are being used, and tells TeamChat and Chat what to do.

void

TeamChat ( string message )

Makes the LocalPlayer chat the given message, which will only be viewable by users on the same team

void

WhisperChat ( string message , Instance player )

Delivers the given message to a recipient without anyone else seeing

Instance

getPlayerFromCharacter ( Instance character )

[Deprecated]
Objects

getPlayers ( )

[Deprecated]
Instance

playerFromCharacter ( Instance character )

[Deprecated]

.

Objects

players ( )

[Deprecated]

Returns a list of players in a game

Inherited from Instance: Show Hide

void

ClearAllChildren ( )

This function destroys all of an Instance's children.

Instance

Clone ( )

Create a deep copy of a Roblox instance and descendants where Archivable = true.

void

Destroy ( )

Sets the Instance/Parent property to nil, locks the Instance/Parent property, disconnects all connections and calls Destroy on all children.

Instance

FindFirstAncestor ( string name )

Returns the first ancestor of the Instance whose Instance/Name is equal to the given name.

Instance

FindFirstAncestorOfClass ( string className )

Returns the first ancestor of the Instance whose Instance/ClassName is equal to the given className.

Instance

FindFirstAncestorWhichIsA ( string className )

Returns the first ancestor of the Instance for whom Instance/IsA returns true for the given className.

Instance

FindFirstChild ( string name , bool recursive )

Returns the first child of the Instance found with the given name.

Instance

FindFirstChildOfClass ( string className )

Returns the first child of the Instance whose Instance/ClassName|ClassName is equal to the given className.

Instance

FindFirstChildWhichIsA ( string className , bool recursive )

Returns the first child of the Instance for whom Instance/IsA returns true for the given className.

Variant

GetAttribute ( string attribute )

Returns the attribute which has been assigned to the given name

RBXScriptSignal

GetAttributeChangedSignal ( string attribute )

Returns an event that fires when the given attribute changes

Dictionary

GetAttributes ( )

Attributes are not currently enabled, so this API member may have no effect, emit a warning or raise an error. Do not use it in new work.

Returns a dictionary of string → variant pairs for each of the Instance|Instance’s attributes

Objects

GetChildren ( )

Returns an array containing all of the Instance's children.

string

GetDebugId ( int scopeLength )

[NotBrowsable]

Returns a coded string of the Instances DebugId used internally by Roblox.

Array

GetDescendants ( )

[CustomLuaState]

Returns an array containing all of the descendants of the instance

string

GetFullName ( )

Returns a string describing the Instance's ancestry.

RBXScriptSignal

GetPropertyChangedSignal ( string property )

Get an event that fires when a given property of an object changes.

bool

IsA ( string className )

[CustomLuaState]

Returns true if an Instance's class matches or inherits from a given class

bool

IsAncestorOf ( Instance descendant )

Returns true if an Instance is an ancestor of the given descendant.

bool

IsDescendantOf ( Instance ancestor )

Returns true if an Instance is a descendant of the given ancestor.

void

Remove ( )

[Deprecated]

Sets the object’s Parent to nil, and does the same for all its descendants.

void

SetAttribute ( string attribute , Variant value )

Sets the attribute with the given name to the given value

Instance

WaitForChild ( string childName , double timeOut )

[CustomLuaState] [CanYield]

Returns the child of the Instance with the given name. If the child does not exist, it will yield the current thread until it does.

Objects

children ( )

[Deprecated]

Returns an array of the object’s children.

Instance

clone ( )

[Deprecated]
void

destroy ( )

[Deprecated]
Instance

findFirstChild ( string name , bool recursive )

[Deprecated]
Objects

getChildren ( )

[Deprecated]
bool

isA ( string className )

[Deprecated] [CustomLuaState]
bool

isDescendantOf ( Instance ancestor )

[Deprecated]
void

remove ( )

[Deprecated]

Events

RBXScriptSignal

PlayerAdded ( Instance player )

Fires when a player enters the game.

RBXScriptSignal

PlayerChatted ( PlayerChatType chatType , Instance player , string message , Instance targetPlayer )

Fired when a player chats.

RBXScriptSignal

PlayerConnecting ( Instance player )

Fired when a player is connecting to the game.

RBXScriptSignal

PlayerDisconnecting ( Instance player )

Fired when a player is disconnecting from the game.

RBXScriptSignal

PlayerMembershipChanged ( Instance player )

Fires when the game server recognizes that a player’s membership has changed

RBXScriptSignal

PlayerRejoining ( Instance player )

Fired when a player rejoins a game session after having disconnected prior.

RBXScriptSignal

PlayerRemoving ( Instance player )

Fires when a player is about to leave the game.

Inherited from Instance: Show Hide

RBXScriptSignal

AncestryChanged ( Instance child , Instance parent )

Fires when the Instance/Parent property of the object or one of its ancestors is changed.

RBXScriptSignal

AttributeChanged ( string attribute )

Fires whenever an attribute is changed on the Instance

RBXScriptSignal

Changed ( string property )

[DetectingPropertyChanges]

Fired immediately after a property of an object changes.

RBXScriptSignal

ChildAdded ( Instance child )

Fires when an object is parented to this Instance.

RBXScriptSignal

ChildRemoved ( Instance child )

Fires when a child is removed from this Instance.

RBXScriptSignal

DescendantAdded ( Instance descendant )

Fires when a descendant is added to the Instance

RBXScriptSignal

DescendantRemoving ( Instance descendant )

Fires immediately before a descendant of the Instance is removed.

RBXScriptSignal

childAdded ( Instance child )

[Deprecated]

Code Samples


Give Sparkles to Everyone

This code sample listens for players spawning and gives them Sparkles in their head. It does this by defining two functions, onPlayerSpawned and onPlayerAdded. It calls these functions for players/characters already in the game, in case the script runs after players already arrive.