Source: Roblox Creator Hub · CC BY 4.0 · View source · Code samples: MIT Imported 2026-10-03. Formatting adapted for this site.
Players
Inherits from: Instance → Object
The Players service contains Player objects for presently connected clients to a Roblox server. It also contains information about a place's configuration. It can fetch information about players not connected to the server, such as character appearances, friends, and avatar thumbnail.
Inherits from: Instance
Memory category: Instances
Tags: NotCreatable, Service
Properties
| Name | Type / Returns | Description |
|---|---|---|
| Players.BanningEnabled | boolean | Enables or disables the three Players methods (BanAsync(), UnbanAsync(), and GetBanHistoryAsync()) that constitute the ban API. This property cannot be set through developer-facing Luau and must be set in Studio through the Players properties window. |
| Players.BubbleChat | boolean | Indicates whether or not bubble chat is enabled. It is set with the Players:SetChatStyle() method. |
| Players.CharacterAutoLoads | boolean | Indicates whether characters will respawn automatically. |
| Players.ClassicChat | boolean | Indicates whether or not classic chat is enabled; set by the Players:SetChatStyle() method. |
| Players.LocalPlayer | Player | The Player that the LocalScript is running for. |
| Players.localPlayer | Player | |
| Players.MaxPlayers | int | The maximum number of players that can be in a server. |
| Players.NumPlayers | int | Returns the number of people in the server at the current time. |
| Players.numPlayers | int | Returns the number of people in the server at the current time. |
| Players.PreferredPlayers | int | The preferred number of players for a server. |
| Players.RespawnTime | float | Controls the amount of time taken for a players character to respawn. |
| Players.UseStrafingAnimations | boolean | Determines whether R15 character models play directional strafing and backpedaling animations instead of always turning to face their direction of movement. |
Inherited from Instance
| Name | Type / Returns | Description |
|---|---|---|
| Instance.Archivable | boolean | Determines if an Instance and its descendants can be cloned using Instance:Clone(), and can be saved/published. |
| Instance.archivable | boolean | |
| Instance.Capabilities | SecurityCapabilities | The set of capabilities allowed to be used for scripts inside this container. |
| Instance.IsInSandbox | boolean | Indicates whether the instance is inside a sandboxed container. |
| Instance.Name | string | A non-unique identifier of the Instance. |
| Instance.Parent | Instance | Determines the hierarchical parent of the Instance. |
| Instance.PredictionMode | PredictionMode | Reflects the client-side prediction mode applied to the instance under server-authoritative physics. |
| Instance.RobloxLocked | boolean | A deprecated property that used to protect CoreGui objects. |
| Instance.Sandboxed | boolean | When enabled, the instance can only access abilities in its Capabilities list. |
| Instance.UniqueId | UniqueId | A unique identifier for the instance. |
Inherited from Object
| Name | Type / Returns | Description |
|---|---|---|
| Object.ClassName | string | A read-only string representing the class this Object belongs to. |
| Object.className | string |
Players.BanningEnabled
Enables or disables the three Players methods (BanAsync(), UnbanAsync(), and GetBanHistoryAsync()) that constitute the ban API. This property cannot be set through developer-facing Luau and must be set in Studio through the Players properties window.
| Field | Value |
|---|---|
| type | boolean |
| tags | ["NotScriptable"] |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Behavior |
| serialization | {"can_load":true,"can_save":true} |
| capabilities | ["Players"] |
Players.BubbleChat
This property indicates whether or not bubble chat is enabled. It is set with the Players:SetChatStyle() method using the ChatStyle enum.
When this chat mode is enabled, the experience displays chats in the chat user interface at the top-left corner of the screen.
There are two other chat modes, Players.ClassicChat and a chat mode where both classic and bubble chat are enabled.
| Field | Value |
|---|---|
| type | boolean |
| tags | ["ReadOnly","NotReplicated"] |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Data |
| serialization | {"can_load":false,"can_save":false} |
| capabilities | ["Chat","Players"] |
Players.CharacterAutoLoads
This property indicates whether characters will respawn automatically. The default value is true.
If this property is disabled (false), player characters will not spawn until the Player:LoadCharacterAsync() function is called for each Player, including when players join the experience.
This can be useful in experiences where players have finite lives, such as competitive experiences in which players do not respawn until a round ends.
| Field | Value |
|---|---|
| type | boolean |
| tags | ["NotReplicated"] |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Behavior |
| serialization | {"can_load":true,"can_save":true} |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (player-respawn-timer).
Players.ClassicChat
Indicates whether or not classic chat is enabled. This property is set by the Players:SetChatStyle() method using the ChatStyle enum.
When this chat mode is enabled, the experience displays chats in a bubble above the sender's head.
There are two other chat modes, Players.BubbleChat and a chat mode where both classic and bubble chat are enabled.
| Field | Value |
|---|---|
| type | boolean |
| tags | ["ReadOnly","NotReplicated"] |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Data |
| serialization | {"can_load":false,"can_save":false} |
| capabilities | ["Chat","Players"] |
Players.LocalPlayer
This read-only property refers to the Player whose client is running the experience.
This property is only defined for LocalScripts and ModuleScripts required by them, since they run on the client. For the server, on which Script objects run their code, this property is nil.
| Field | Value |
|---|---|
| type | Player |
| tags | ["ReadOnly","NotReplicated"] |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Data |
| serialization | {"can_load":false,"can_save":false} |
| capabilities | ["Players"] |
Players.localPlayer
Deprecated. This property is a deprecated variant of Players.LocalPlayer which should be used instead.
| Field | Value |
|---|---|
| type | Player |
| tags | ["Hidden","ReadOnly","NotReplicated","Deprecated"] |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Data |
| serialization | {"can_load":false,"can_save":false} |
| capabilities | ["Players"] |
Players.MaxPlayers
This property determines the maximum number of players that can be in a server. This property can only be set through a specific place's settings on the Creator Dashboard.
| Field | Value |
|---|---|
| type | int |
| tags | ["ReadOnly","NotReplicated"] |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Data |
| serialization | {"can_load":false,"can_save":false} |
| capabilities | ["Players"] |
Players.NumPlayers
Deprecated. This item is deprecated. Instead, of using this item, you should count the number of players returned by Players:GetPlayers().
This property indicates the number of people in the server at the current time. It is read only. Meaning it cannot be written to, only read.
| Field | Value |
|---|---|
| type | int |
| tags | ["ReadOnly","NotReplicated","Deprecated"] |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Data |
| serialization | {"can_load":false,"can_save":false} |
| capabilities | ["Players"] |
Players.numPlayers
Deprecated. This property is a deprecated variant of Players.NumPlayers which has also been deprecated. Neither property should be used in new work. Instead, you should count the number of players returned by Players:GetPlayers().
This property indicates the number of people in the server at the current time. It is read only. Meaning it cannot be written to, only read.
| Field | Value |
|---|---|
| type | int |
| tags | ["Hidden","ReadOnly","NotReplicated","Deprecated"] |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Data |
| serialization | {"can_load":false,"can_save":false} |
| capabilities | ["Players"] |
Players.PreferredPlayers
This property indicates the number of players to which Roblox's matchmaker will fill servers. This number will be less than the maximum number of players (Players.MaxPlayers) supported by the experience.
| Field | Value |
|---|---|
| type | int |
| tags | ["ReadOnly","NotReplicated"] |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Data |
| serialization | {"can_load":false,"can_save":false} |
| capabilities | ["Players"] |
Players.RespawnTime
This property controls the time, in seconds, it takes for a player to respawn when Players.CharacterAutoLoads is true. It defaults to 5.0 seconds.
This is useful when you want to change how long it takes to respawn based on the type of your experience but don't want to handle spawning players individually.
Although this property can be set from within a Script, you can more easily set it directly on the Players object in Studio's Explorer window.
| Field | Value |
|---|---|
| type | float |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Data |
| serialization | {"can_load":true,"can_save":true} |
| capabilities | ["Players"] |
Players.UseStrafingAnimations
When enabled, R15 character Humanoids play directional locomotion animations, strafing sideways and backpedaling while keeping their current facing direction instead of rotating to face whichever direction they move. When disabled, characters turn to face their direction of movement. Defaults to false.
This property cannot be set through developer-facing Luau and must be set in Studio through the Players properties window.
| Field | Value |
|---|---|
| type | boolean |
| tags | ["NotScriptable"] |
| security | {"read":"None","write":"None"} |
| thread safety | ReadSafe |
| category | Behavior |
| serialization | {"can_load":true,"can_save":true} |
| capabilities | ["Players"] |
Methods
| Name | Type / Returns | Description |
|---|---|---|
| Players:BanAsync | () | Bans users from your experience, with options to specify duration, reason, whether the ban applies to the entire universe or just the current place, and more. This method is enabled and disabled by the Players.BanningEnabled property, which you can toggle in Studio. |
| Players:Chat | () | Makes the local player chat the given message. |
| Players:CreateHumanoidModelFromDescription | Model | Returns a character Model equipped with everything specified in the passed in HumanoidDescription. |
| Players:CreateHumanoidModelFromDescriptionAsync | Model | Returns a character Model equipped with everything specified in the passed in HumanoidDescription. If HumanoidDescription.UseAvatarSettings is set to true, Avatar Settings in the experience will be applied to the returned model. |
| Players:CreateHumanoidModelFromUserId | Model | Returns a character Model set-up with everything equipped to match the avatar of the user specified by the passed in userId. |
| Players:CreateHumanoidModelFromUserIdAsync | Model | Returns a character Model set-up with everything equipped to match the avatar of the user specified by the passed in userId. |
| Players:GetBanHistoryAsync | BanHistoryPages | Retrieves the ban and unban history of any user within the experience's universe. This method is enabled and disabled by the Players.BanningEnabled property, which you can toggle in Studio. |
| Players:GetCharacterAppearanceAsync | Model | Returns a Model containing the assets which the player is wearing, excluding gear. |
| Players:GetCharacterAppearanceInfoAsync | Dictionary | Returns information about the character appearance of a given user. |
| Players:GetFriendsAsync | FriendPages | Returns a FriendPages object which contains information for all of the given player's friends. |
| Players:GetHumanoidDescriptionFromOutfitId | HumanoidDescription | Returns the HumanoidDescription for a specified outfit, which will be set with the parts/colors/Animations etc of the outfit. |
| Players:GetHumanoidDescriptionFromOutfitIdAsync | HumanoidDescription | Returns the HumanoidDescription for a specified outfit, which will be set with the parts/colors/Animations etc of the outfit. |
| Players:GetHumanoidDescriptionFromUserId | HumanoidDescription | Returns a HumanoidDescription which specifies everything equipped for the avatar of the user specified by the passed in userId. |
| Players:GetHumanoidDescriptionFromUserIdAsync | HumanoidDescription | Returns a HumanoidDescription which specifies everything equipped for the avatar of the user specified by the passed in userId. |
| Players:GetNameFromUserIdAsync | string | Sends a query to the Roblox website for the username of an account with a given UserId. |
| Players:GetPlayerByUserId | Player | Returns the Player with the given UserId if they are in-experience. |
| Players:GetPlayerFromCharacter | Player | Returns the Player whose Player.Character matches the given instance, or nil if one cannot be found. |
| Players:GetPlayers | List | Returns a table of all presently connected Player objects. |
| Players:getPlayers | List | |
| Players:GetProfileConfigurationFromUserIdAsync | ProfileConfiguration | Returns the profile configuration of a user as a dictionary. |
| Players:GetUserIdFromNameAsync | int64 | Sends a query to the Roblox website for the userId of an account with a given username. |
| Players:GetUserThumbnailAsync | Tuple | Returns the content URL of a player thumbnail given the size and type, as well as a boolean describing if the image is ready to use. |
| Players:playerFromCharacter | Player | |
| Players:players | List | Returns a list of players in an experience. |
| Players:SetChatStyle | () | Sets whether BubbleChat and ClassicChat are being used, and tells TeamChat and Chat what to do. |
| Players:TeamChat | () | Makes the local player chat the given message, which will only be viewable by users on the same team. |
| Players:UnbanAsync | () | Unbans players banned from Players:BanAsync() or the User Restrictions Open Cloud API. This method is enabled and disabled by the Players.BanningEnabled property, which you can toggle in Studio. |
Inherited from Instance
| Name | Type / Returns | Description |
|---|---|---|
| Instance:AddTag | () | Applies a tag to the instance. |
| Instance:children | Instances | Returns an array of the object's children. |
| Instance:ClearAllChildren | () | This method destroys all of an instance's children. |
| Instance:Clone | Instance | Create a copy of an instance and all its descendants, ignoring instances that are not Archivable. |
| Instance:clone | Instance | |
| Instance:Destroy | () | Sets the Instance.Parent property to nil, locks the Instance.Parent property, disconnects all connections, and calls Destroy() on all children. |
| Instance:destroy | () | |
| Instance:FindFirstAncestor | Instance? | Returns the first ancestor of the Instance whose Instance.Name is equal to the given name. |
| Instance:FindFirstAncestorOfClass | Instance? | Returns the first ancestor of the Instance whose Object.ClassName is equal to the given className. |
| Instance:FindFirstAncestorWhichIsA | Instance? | Returns the first ancestor of the Instance for whom Object:IsA() returns true for the given className. |
| Instance:FindFirstChild | Instance? | Returns the first child of the Instance found with the given name. |
| Instance:findFirstChild | Instance | |
| Instance:FindFirstChildOfClass | Instance? | Returns the first child of the Instance whose ClassName is equal to the given class name. |
| Instance:FindFirstChildWhichIsA | Instance? | Returns the first child of the Instance for whom Object:IsA() returns true for the given className. |
| Instance:FindFirstDescendant | Instance? | Returns the first descendant found with the given Instance.Name. |
| Instance:GetActor | Actor? | Returns the Actor associated with the Instance, if any. |
| Instance:GetAttribute | Variant | Returns the value which has been assigned to the given attribute name. |
| Instance:GetAttributeChangedSignal | RBXScriptSignal | Returns an event that fires when the given attribute changes. |
| Instance:GetAttributes | Dictionary | Returns a dictionary of the instance's attributes. |
| Instance:GetChildren | Instances | Returns an array containing all of the instance's children. |
| Instance:getChildren | Instances | |
| Instance:GetDebugId | string | Returns a coded string of the debug ID used internally by Roblox. |
| Instance:GetDescendants | Instances | Returns an array containing all of the descendants of the instance. |
| Instance:GetFullName | string | Returns a string describing the instance's ancestry. |
| Instance:GetStyled | Variant | Returns the styled or explicitly modified value of the specified property, or else the default property value if it hasn't been styled/modified. |
| Instance:GetStyledPropertyChangedSignal | RBXScriptSignal | Returns an event that fires when the given style property changes on the instance. |
| Instance:GetTags | Array | Gets an array of all tags applied to the instance. |
| Instance:HasTag | boolean | Check whether the instance has a given tag. |
| Instance:IsAncestorOf | boolean | Returns true if an Instance is an ancestor of the given descendant. |
| Instance:IsDescendantOf | boolean | Returns true if an Instance is a descendant of the given ancestor. |
| Instance:isDescendantOf | boolean | |
| Instance:IsPropertyModified | boolean | Returns true if the value stored in the specified property is not equal to the code-instantiated default. |
| Instance:QueryDescendants | Instances | Returns an array containing all descendants of the instance that match the selector string. |
| Instance:Remove | () | Sets the object's Parent to nil, and does the same for all its descendants. |
| Instance:remove | () | |
| Instance:RemoveTag | () | Removes a tag from the instance. |
| Instance:ResetPropertyToDefault | () | Resets a property to its default value. |
| Instance:SetAttribute | () | Sets the attribute with the given name to the given value. |
| Instance:WaitForChild | Instance | 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. |
Inherited from Object
| Name | Type / Returns | Description |
|---|---|---|
| Object:GetPropertyChangedSignal | RBXScriptSignal | Get an event that fires when a given property of the object changes. |
| Object:IsA | boolean | Returns true if an object's class matches or inherits from a given class. |
| Object:isA | boolean |
Players:BanAsync
The Players:BanAsync() method allows you to easily ban users who violate your experience's guidelines. You can specify the ban duration, enable the ban to propagate to suspected alternate accounts, enable the ban to temporarily block the banned user's device from rejoining the experience, and provide a message to the banned user in accordance with the Usage Guidelines. You should also post your experience rules somewhere accessible to all users and provide a way for them to appeal. This method is enabled and disabled by the Players.BanningEnabled property, which you can toggle in Studio.
Banning and Messaging
Banned users will be immediately evicted and prevented from rejoining your experiences. They will be presented with an error modal displaying the time left on their ban and your DisplayReason. Roblox's backend systems will evict players across all servers from the place(s) that you specify. DisplayReason can have a maximum length of 400 characters and is subject to a text filter. For more information on acceptable modal text, see ban messaging.
Places and Universe
By default, bans extend to any place within that universe. To limit the ban to only the place from which this API is called, configure ApplyToUniverse to false. However, if a user is banned in the start place of the universe, it effectively results in the user being excluded from the entirety of the universe, irrespective of whether a universal ban is in place or not.
Alternative Accounts
Users often play under multiple different accounts, known as alternate accounts, which are sometimes used to circumvent account bans. To help you keep banned users out, the default behavior of this API will propagate all bans from the source account you banned to any of their suspected alternate accounts. You can turn off ban propagations to alternate accounts by configuring ExcludeAltAccounts to true.
Device Blocks
To help address disruptive users who circumvent alternate account detection, set ApplyDeviceBlock to true. This blocks the banned user's device from rejoining the experience for 24 hours after the ban is applied.
Ban Duration
Not all transgressions are the same, so not all bans should be the same length. This API lets you configure the duration of the ban, in seconds, with the Duration field. To specify a permanent ban, set the field to -1. You may also want to dynamically configure the ban duration based on the user's ban history, which you can query for using Players:GetBanHistoryAsync(). For example, you may want to consider the number of bans, the duration of previous bans, or build logic off of the notes you save under PrivateReason which can be up to 1000 characters and are not text filtered. PrivateReason notes are never shared with the client and can be considered safe from attackers.
Errors and Throttling
This method invokes an HTTP call to backend services which are subject to throttling and may fail. If you're calling this API with more than one UserId, this method will attempt to make the HTTP call for each ID. It will then aggregate any error messages and join them as a comma separated list. For example, if this method is invoked for five users and requests for those with UserIds 2 and 4 fail, the following error message appears:
HTTP failure for UserId 2: Timedout, HTTP 504 (Service unavailable) failure for UserId 4: Service exception
The message will always include failure for UserId {} if it is an HTTP error.
Client-Side Requirement
Because of the risks associated with banning users, this method may only be called on the backend experience server (client-side calls will result in an error). You may test this API in Studio, during collaborative creation, or in a team test, but the bans will not apply to production.
This API uses the User Restrictions Open Cloud API. You will be able to utilize these APIs to manage your bans in third party applications.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| config | Dictionary | - UserIds (required; array) — Array of UserIds of players to be banned. Max size is 50. - ApplyToUniverse (optional; boolean) — Whether ban propagates to all places within the experience universe. Default is true. - Duration (required; integer) — Duration of the ban, in seconds. Permanent bans should have a value of -1. 0 and all other negative values are invalid. - DisplayReason (required; string) — The message that will be displayed to users when they attempt to and fail to join an experience. Maximum string length is 400. - PrivateReason (required; string) — Internal messaging that will be returned when querying the user's ban history. Maximum string length is 1000. - ExcludeAltAccounts (optional; boolean) — When true, Roblox does not attempt to ban alternate accounts. Default is false. - ApplyDeviceBlock (optional; boolean) — When true, Roblox will block banned users' devices from rejoining the experience for 24 hours after the ban is applied. Default is false. The block can be overridden by unbanning a user via a call to Players:UnbanAsync(). Note that unbanning a user through any other method will not lift the device block. |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players","Consequences"] |
Code samples: View on Creator Hub (Players-Ban).
Players:Chat
This function makes the local player chat the given message. Since this item is protected, attempting to use it in a Script or LocalScript will cause an error.
Instead, when creating a custom chat system, or a system that needs access to the chat, you can use the Chat service's Chat:Chat() function instead.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| message | string | The message chatted. |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| security | PluginSecurity |
| thread safety | Unsafe |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (Players-Chat1).
Players:CreateHumanoidModelFromDescription
Deprecated. This method has been superseded by CreateHumanoidModelFromDescriptionAsync().
Returns a character Model equipped with everything specified in the passed in HumanoidDescription, and is R6 or R15 as specified by rigType. This method has been superseded by CreateHumanoidModelFromDescriptionAsync(), which should be used in new work.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| description | HumanoidDescription | Specifies the appearance of the returned character. | |
| rigType | HumanoidRigType | Specifies whether the returned character will be R6 or R15. | |
| assetTypeVerification | AssetTypeVerification | Default | The asset type verification mode. |
Returns
| Type | Description |
|---|---|
| Model | A Humanoid character Model. |
| Field | Value |
|---|---|
| tags | ["Yields","Deprecated"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["AvatarAppearance","Players"] |
Players:CreateHumanoidModelFromDescriptionAsync
Returns a character Model equipped with everything specified in the passed in HumanoidDescription, and is R6 or R15 as specified by rigType.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| description | HumanoidDescription | Specifies the appearance of the returned character. | |
| rigType | HumanoidRigType | Specifies whether the returned character will be R6 or R15. | |
| assetTypeVerification | AssetTypeVerification | Default | The asset type verification mode. |
Returns
| Type | Description |
|---|---|
| Model | A Humanoid character Model. |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["AvatarAppearance","Players"] |
Code samples: View on Creator Hub (create-humanoid-model-from-description).
Players:CreateHumanoidModelFromUserId
Deprecated. This method has been superseded by CreateHumanoidModelFromUserIdAsync().
Returns a character Model set up with everything equipped to match the avatar of the user specified by the passed in userId, including whether that character is currently R6 or R15. This method has been superseded by CreateHumanoidModelFromUserIdAsync(), which should be used in new work.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| userId | User | The userId for a Roblox user. (The UserId is the number in the profile of the user e.g www.roblox.com/users/1/profile). |
Returns
| Type | Description |
|---|---|
| Model | A Humanoid character Model. |
| Field | Value |
|---|---|
| tags | ["Yields","Deprecated"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (create-humanoid-model-from-userid).
Players:CreateHumanoidModelFromUserIdAsync
Returns a character Model set-up with everything equipped to match the avatar of the user specified by the passed in userId. This includes whether that character is currently R6 or R15.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| userId | User | The userId for a Roblox user. (The UserId is the number in the profile of the user e.g www.roblox.com/users/1/profile). |
Returns
| Type | Description |
|---|---|
| Model | A Humanoid character Model. |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (create-humanoid-model-from-userid).
Players:GetBanHistoryAsync
Retrieves the ban and unban history of any user within the experience's universe. This method returns a BanHistoryPages instance that inherits from Pages. This method is enabled and disabled by the Players.BanningEnabled property, which you can toggle in Studio.
This function call will only succeed on production servers and not on client devices or in Studio.
This API uses the User Restrictions Open Cloud API. You will be able to utilize these APIs to manage your bans in third party applications.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| userId | User | The Player.UserId of the player whose ban history to retrieve. |
Returns
| Type | Description |
|---|---|
| BanHistoryPages | See BanHistoryPages for return reference. |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players","Consequences"] |
Players:GetCharacterAppearanceAsync
Deprecated. This method is deprecated. Do not use it for new work.
This function returns a Model containing the assets which the player is wearing, excluding gear.
If you prefer a Luau table of information about these assets instead of a model, use Players:GetCharacterAppearanceInfoAsync().
This method behaves similar to InsertService:LoadAsset(), and is like using LoadAsset on the asset information returned by Players:GetCharacterAppearanceInfoAsync() except faster.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| userId | User | The Player.UserId of the specified player. |
Returns
| Type | Description |
|---|---|
| Model | A Model containing the assets the player is wearing, excluding gear. |
| Field | Value |
|---|---|
| tags | ["Yields","Deprecated"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (how-to-get-a-character-s-appearance).
Players:GetCharacterAppearanceInfoAsync
This function returns information about a player's avatar on the Roblox website in the form of a dictionary. It is not to be confused with GetCharacterAppearanceAsync, which actually loads the assets described by this method. You can use InsertService:LoadAsset() to load the assets that are used in the player's avatar. The structure of the returned dictionary is as follows:
| Name | Type | Description |
|---|---|---|
assets | table (see below) | Describes the equipped assets (hats, body parts, etc) |
bodyColors | table (see below) | Describes the BrickColor values for each limb |
bodyColor3s | table (see below) | Describes the Color3 instance for each limb which may not match perfectly with bodyColors |
defaultPantsApplied | bool | Describes whether default pants are applied |
defaultShirtApplied | bool | Describes whether default shirt is applied |
emotes | table (see below) | Describes the equipped emote animations |
playerAvatarType | string | Either "R15" or "R6" |
scales | table (see below) | Describes various body scaling factors |
Assets Sub-Table
The assets table is an array of tables containing the following keys that describe the assets currently equipped by the player:
| Name | Type | Description |
|---|---|---|
id | number | The asset ID of the equipped asset |
assetType | table | A table with name and id fields, each describing the kind of asset equipped ("Hat", "Face", etc.) |
name | string | The name of the equipped asset |
Scales Sub-Table
The scales table has the following keys, each a number corresponding to one Humanoid scaling property: bodyType, head, height, proportion, depth, width.
Body Colors Sub-Table
The bodyColors table has the following keys, each a number corresponding to a BrickColor ID number which can be used with BrickColor.new(id): leftArmColorId, torsoColorId, rightArmColorId, headColorId, leftLegColorId, rightLegColorId.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| userId | User | The *userId of the specified player. |
Returns
| Type | Description |
|---|---|
| Dictionary | A dictionary containing information about the character appearance of a given user. |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (example-return-dictionary).
Players:GetFriendsAsync
The GetFriends Players function returns a FriendPages object which contains information for all of the given user's friends. The items within the FriendPages object are tables with the following fields:
| Name | Type | Description |
|---|---|---|
| Id | int64 | The friend's UserId |
| Username | string | The friend's username |
| DisplayName | string | The Class.Player.DisplayName|display name of the friend. |
See the code samples for an easy way to iterate over all a player's friends.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| userId | User | The user ID of the player being specified. |
Returns
| Type | Description |
|---|---|
| FriendPages | A FriendPages object containing information for all of the given user's friends. |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players","Social"] |
Code samples: View on Creator Hub (print-roblox-friends).
Players:GetHumanoidDescriptionFromOutfitId
Deprecated. This method has been superseded by GetHumanoidDescriptionFromOutfitIdAsync().
Returns the HumanoidDescription for the specified outfitId, set with the parts, colors, animations, and other properties of the outfit. An outfit can be one created by a user, or the outfit for a bundle created by Roblox. This method has been superseded by GetHumanoidDescriptionFromOutfitIdAsync(), which should be used in new work.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| outfitId | int64 | The ID of the outfit for which the HumanoidDescription is sought. |
Returns
| Type | Description |
|---|---|
| HumanoidDescription | HumanoidDescription initialized with the specification for the passed in outfitId. |
| Field | Value |
|---|---|
| tags | ["Yields","Deprecated"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["AvatarAppearance","Players"] |
Code samples: View on Creator Hub (get-humanoiddescription-from-outfitid).
Players:GetHumanoidDescriptionFromOutfitIdAsync
Returns the HumanoidDescription for a specified outfitId, which will be set with the parts/colors/Animations etc of the outfit. An outfit can be one created by a user, or it can be the outfit for a bundle created by Roblox.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| outfitId | int64 | The ID of the outfit for which the HumanoidDescription is sought. |
Returns
| Type | Description |
|---|---|
| HumanoidDescription | HumanoidDescription initialized with the specification for the passed in outfitId. |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["AvatarAppearance","Players"] |
Code samples: View on Creator Hub (get-humanoiddescription-from-outfitid).
Players:GetHumanoidDescriptionFromUserId
Deprecated. This method has been superseded by GetHumanoidDescriptionFromUserIdAsync().
Returns a HumanoidDescription which specifies everything equipped for the avatar of the user specified by the passed in userId, including scales and body colors. This method has been superseded by GetHumanoidDescriptionFromUserIdAsync(), which should be used in new work.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| userId | User | The userId for a Roblox user. (The UserId is the number in the profile of the user e.g www.roblox.com/users/1/profile). |
Returns
| Type | Description |
|---|---|
| HumanoidDescription | HumanoidDescription initialized with the passed in user's avatar specification. |
| Field | Value |
|---|---|
| tags | ["Yields","Deprecated"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["AvatarAppearance","Players"] |
Code samples: View on Creator Hub (get-humanoiddescription-from-userid).
Players:GetHumanoidDescriptionFromUserIdAsync
Returns a HumanoidDescription which specifies everything equipped for the avatar of the user specified by the passed in userId. Also includes scales and body colors.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| userId | User | The userId for a Roblox user. (The UserId is the number in the profile of the user e.g www.roblox.com/users/1/profile). |
Returns
| Type | Description |
|---|---|
| HumanoidDescription | HumanoidDescription initialized with the passed in user's avatar specification. |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["AvatarAppearance","Players"] |
Code samples: View on Creator Hub (get-humanoiddescription-from-userid).
Players:GetNameFromUserIdAsync
The GetNameFromUserIdAsync Players function will send a query to the Roblox website asking what the username is of the account with the given UserId.
This method errors if no account exists with the given UserId. If you aren't certain such an account exists, it's recommended to wrap calls to this function with LuaGlobals.pcall(). In addition, you can manually cache results to make future calls with the same UserId fast. See the code samples to learn more.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| userId | User | The Player.UserId of the player being specified. |
Returns
| Type | Description |
|---|---|
| string | The name of a user with the specified Player.UserId. |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (Name-From-UserId, Name-From-UserId-Cache).
Players:GetPlayerByUserId
This function searches each Player in Players for one whose Player.UserId matches the given userId. If such a player does not exist, it returns nil.
This method is useful in finding the purchaser of a developer product using MarketplaceService.ProcessReceipt which provides a table that includes the purchaser's UserId and not a reference to the Player object itself. Most experiences will require a reference to the player in order to grant products.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| userId | User | The Player.UserId of the player being specified. |
Returns
| Type | Description |
|---|---|
| Player | The Player with the given Player.UserId, or nil if no connected player has that UserId. |
| Field | Value |
|---|---|
| security | None |
| thread safety | Safe |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (Players-GetPlayerByUserId1).
Players:GetPlayerFromCharacter
This function returns the Player associated with the given Player.Character, or nil if one cannot be found. It is equivalent to the following function:
local function getPlayerFromCharacter(character)
for _, player in game:GetService("Players"):GetPlayers() do
if player.Character == character then
return player
end
end
end This method is often used when some event in player's character fires (such as their Humanoid dying). Such an event might not directly reference the Player object, but this method provides easy access. The inverse of this function can be described as getting the Character of a Player. To do this, simply access the Character property.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| character | Model | A character instance that you want to get the player from. |
Returns
| Type | Description |
|---|---|
| Player | The Player whose Player.Character matches the given model, or nil if one cannot be found. |
| Field | Value |
|---|---|
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players"] |
| simulationAccess | true |
Code samples: View on Creator Hub (Players-GetPlayerFromCharacter1).
Players:GetPlayers
This method returns a table of all presently connected Player objects. It functions the same way Instance:GetChildren() would except that it only returns Player objects found under Players. When used with a for loop, it is useful for iterating over all players in an experience.
local Players = game:GetService("Players")
for _, player in Players:GetPlayers() do
print(player.Name)
end Scripts that connect to Players.PlayerAdded are often trying to process every Player that connects to the experience. This method is useful for iterating over already-connected players that wouldn't fire PlayerAdded. Using this method ensures that no player is missed!
local Players = game:GetService("Players")
local function onPlayerAdded(player)
print("Player: " .. player.Name)
end
for _, player in Players:GetPlayers() do
onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded) Returns
| Type | Description |
|---|---|
| List | A table containing all the players in the server. |
| Field | Value |
|---|---|
| security | None |
| thread safety | Safe |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (Give-Sparkles-to-Everyone).
Players:getPlayers
Deprecated. This function is a deprecated variant of Players:GetPlayers() which should be used instead.
Returns
| Type | Description |
|---|---|
| List |
| Field | Value |
|---|---|
| tags | ["Deprecated"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players"] |
Players:GetProfileConfigurationFromUserIdAsync
Returns the profile configuration of the user specified by the given Player.UserId as a dictionary. The dictionary can include a BackgroundAssetId field for the user's profile background asset ID and a FrameAssetId field for the user's profile frame image asset ID.
Can only be called from the server and is throttled to a limited number of requests per minute.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| userId | User | The Player.UserId of the user whose profile configuration to retrieve. |
Returns
| Type | Description |
|---|---|
| ProfileConfiguration | A dictionary containing the user's profile configuration, such as the background asset ID. |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["AvatarAppearance","Players"] |
Players:GetUserIdFromNameAsync
This function will send a query to the Roblox website asking what the Player.UserId is of the account with the given Player name.
This method errors if no account exists with the given username. If you aren't certain such an account exists, it's recommended to wrap calls to this function with LuaGlobals.pcall(). In addition, you can manually cache results to quickly make future calls with the same username. See the code samples to learn more.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| userName | string | The username of the player being specified. |
Returns
| Type | Description |
|---|---|
| int64 | The Player.UserId of a user whose name is specified. |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (UserId-From-Name, UserId-From-Name-Cache).
Players:GetUserThumbnailAsync
This function returns the content URL of an image of a player's avatar given their UserId, the desired image size as a ThumbnailSize enum, and the desired type as a ThumbnailType enum. It also returns a boolean describing if the image is ready to use.
Most often, this method is used with ImageLabel.Image or Decal.Texture to display user avatar pictures in an experience.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| userId | User | The Player.UserId of the player being specified. | |
| thumbnailType | ThumbnailType | A ThumbnailType describing the type of thumbnail. | |
| thumbnailSize | ThumbnailSize | A ThumbnailSize specifying the size of the thumbnail. |
Returns
| Type | Description |
|---|---|
| Tuple | A tuple containing the content URL of a user thumbnail based on the specified parameters, and a bool describing if the image is ready to be used or not. |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (display-player-thumbnail).
Players:playerFromCharacter
Deprecated. This function is a deprecated variant of Players:GetPlayerFromCharacter() which should be used in new work.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| character | Model |
Returns
| Type | Description |
|---|---|
| Player |
| Field | Value |
|---|---|
| tags | ["Deprecated"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players"] |
Players:players
Deprecated. This item has been superseded by Players:GetPlayers() which should be used in all new work.
This function was once used to return a list of players in an experience, but has since been deprecated in favor of Players:GetPlayers()
Returns
| Type | Description |
|---|---|
| List |
| Field | Value |
|---|---|
| tags | ["Deprecated"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players"] |
Players:SetChatStyle
This function sets whether BubbleChat and ClassicChat are being used, and tells TeamChat and Chat what to do using the ChatStyle enum. Since this item is protected, attempting to use it in a Script or LocalScript will cause an error.
This function is used internally when the chat mode is set by the experience.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| style | ChatStyle | Classic | The specified chat style being set. |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| security | PluginSecurity |
| thread safety | Unsafe |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (setting-a-player-s-chat-style).
Players:TeamChat
This function makes the Players.LocalPlayer chat the given message, which will only be viewable by users on the same team. Since this item is protected, attempting to use it in a Script or LocalScript will cause an error.
This function is used internally when the Players.LocalPlayer sends a message to their team.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| message | string | The message being chatted. |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| security | PluginSecurity |
| thread safety | Unsafe |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (sending-team-chat).
Players:UnbanAsync
Unbans players banned from Players:BanAsync() or the User Restrictions Open Cloud API. This method is enabled and disabled by the Players.BanningEnabled property, which you can toggle in Studio.
Like Players:BanAsync(), this method takes in a config dictionary that will let you bulk unban users. This configures the users that are unbanned and the scope from which they are unbanned from.
Unbans will only take effect on bans with the same ApplyToUniverse scope. For example, an unban with ApplyToUniverse set to true will not invalidate a previous ban with ApplyToUniverse set to false. In other words, a universe level unban will not invalidate a place level ban. The opposite also holds true.
For the case where a user's device may be blocked by a ban where ApplyDeviceBlock was set to true, an unban applied by this method will override the device block for the unbanned player. Please note that unbanning a user through any other method, such as the Open Cloud API or the Creator Hub, will not lift the device block.
This method invokes a HTTP call to backend services, which are throttled and may fail. If you are calling this API with multiple UserIds, this method will attempt to make this HTTP call for each UserId. It will then aggregate any error messages and join them as a comma separated list. For example, if this method is invoked for five UserIds: {1, 2, 3, 4, 5} and requests for users 2 and 4 fail then the following error message appears: HTTP failure for UserId 2: Timedout, HTTP 504 (Service unavailable) failure for UserId 4: Service exception. The message will always include failure for UserId {} if it is an HTTP error. It is undefined behavior if you pass in both valid and invalid UserIds, i.e. a UserId that is not a positive number, as some network requests may succeed before all input is validated.
Because of the risks associated with banning users, this method may only be called on the backend server. Client side calls will result in an error. You may test this API in Studio, Team Create, and Team Test, but the bans will not apply to production. This function call will only attempt ban requests on production servers and not in Studio testing. However, all input validation steps will still work in Studio.
This API uses the User Restrictions Open Cloud API. You will be able to utilize these APIs to manage your bans in third party applications.
Parameters
| Name | Type | Default | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| config | Dictionary |
|
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | None |
| thread safety | Unsafe |
| capabilities | ["Players","Consequences"] |
Code samples: View on Creator Hub (Players-Unban).
Events
| Name | Type / Returns | Description |
|---|---|---|
| Players.PlayerAdded | Fires when a player enters the experience. | |
| Players.PlayerMembershipChanged | Fires when the experience server recognizes that a player's membership has changed. | |
| Players.PlayerRemoving | Fires when a player is about to leave the experience. | |
| Players.UserSubscriptionStatusChanged | Fires when the experience server recognizes that the user's status for a certain subscription has changed. |
Inherited from Instance
| Name | Type / Returns | Description |
|---|---|---|
| Instance.AncestryChanged | Fires when the Instance.Parent property of this object or one of its ancestors is changed. | |
| Instance.AttributeChanged | Fires whenever an attribute is changed on the Instance. | |
| Instance.ChildAdded | Fires after an object is parented to this Instance. | |
| Instance.childAdded | ||
| Instance.ChildRemoved | Fires after a child is removed from this Instance. | |
| Instance.DescendantAdded | Fires after a descendant is added to the Instance. | |
| Instance.DescendantRemoving | Fires immediately before a descendant of the Instance is removed. | |
| Instance.Destroying | Fires immediately before (or is deferred until after) the instance is destroyed via Instance:Destroy(). | |
| Instance.StyledPropertiesChanged | Fires whenever any style property is changed on the instance, including when a property is set to nil. |
Inherited from Object
| Name | Type / Returns | Description |
|---|---|---|
| Object.Changed | Fires immediately after a property of the object changes, with some limitations. |
Players.PlayerAdded
This event fires when a player enters the experience, such as loading the player's saved GlobalDataStore data.
This can be used alongside the Players.PlayerRemoving event, which fires when a player is about to leave the experience. For instance, if you would like print a message every time a new player joins or leaves:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
print(player.Name .. " joined the experience!")
end)
Players.PlayerRemoving:Connect(function(player, reason)
print(player.Name .. " left the experience! Reason: " .. tostring(exitReason))
end) If you want to track when a player's character is added or removed from the experience, such as when a player respawns or dies, you can use the Player.CharacterAdded and Player.CharacterRemoving functions.
Note that this event does not work as expected in a solo playtest mode because the player is created before scripts run that connect to PlayerAdded. To handle this case, as well as cases in which the script is added into the experience after a player enters, create an onPlayerAdded() function that you can call to handle a player's entrance.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| player | Player | An instance of the player that joined the experience. |
| Field | Value |
|---|---|
| security | None |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (Players-PlayerAdded1).
Players.PlayerMembershipChanged
This event fires when the experience server recognizes that a player's membership has changed. Note, however, that the server will only attempt to check and update the membership after the Premium modal has been closed. Thus, to account for cases where the user purchases Premium outside of the experience while playing, you must still prompt them to purchase Premium; this will then show a message telling them they're already upgraded and, once they close the modal, the server will update their membership and trigger this event.
To learn more about and incorporating Premium into your experience and monetizing with the engagement-based payouts system, see Engagement-Based Payouts.
See also:
MarketplaceService:PromptPremiumPurchase(), used to prompt a user to purchase PremiumMarketplaceService.PromptPremiumPurchaseFinished, fires when the Premium purchase UI closes
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| player | Player | The Player whose membership has changed. |
| Field | Value |
|---|---|
| security | None |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (handling-premium-membership-changes).
Players.PlayerRemoving
This event fires right before a Player leaves the experience, before ChildRemoved fires on Players, and behaves somewhat similarly to Instance.DescendantRemoving. Since it fires before the actual removal of a Player, this event is useful for storing player data using a GlobalDataStore.
This can be used alongside the Player.PlayerAdded event, which fires when a player joins the experience. For instance, to print a message every time a new player joins or leaves:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
print(player.Name .. " joined the experience!")
end)
Players.PlayerRemoving:Connect(function(player, exitReason)
print(player.Name .. " left the experience! - Reason: " .. tostring(exitReason))
end) If you want to track when a player's character is added or removed from the experience, such as when a player respawns or dies, you can use the Player.CharacterAdded and Player.CharacterRemoving functions.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| player | Player | An instance of the player that is leaving. | |
| reason | PlayerExitReason | Enum.PlayerExitReason in attempt to inform why. |
| Field | Value |
|---|---|
| security | None |
| capabilities | ["Players"] |
Code samples: View on Creator Hub (Players-PlayerRemoving1).
Players.UserSubscriptionStatusChanged
This event fires when the experience server recognizes that the user's status for a certain subscription has changed. Note that the server only attempts to check and update the status after the Subscription Purchase modal has been closed. To account for cases in which the user purchases the subscription outside of the experience while playing, you must still prompt them to purchase the subscription; the prompt shows a message telling the user they're already subscribed, and after they close the modal, the server updates their subscription status and triggers this event.
Note that only server scripts receive this event.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| user | Player | User whose subscription status has changed. | |
| subscriptionId | string | The ID of the subscription with a status change. |
| Field | Value |
|---|---|
| security | None |
| capabilities | ["Players","Monetization"] |