PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

UserId

Player

int64

The UserId is a Player property that contains a read-only integer that uniquely and consistently identifies every user account on Roblox. Unlike the Instance/Name of a Player, which may change according the user’s present username, this value will never change for the same account.

This property is essential when saving/loading player data using GlobalDataStore|GlobalDataStores. Use a player’s UserId as the data store key so that each player has a unique key.


Code Samples


Players:GetPlayerByUserId


Data Store to Leaderboard

This code sample retrieves a player’s saved gold from a data store and puts the returned value onto the leaderboard. Note that this sample does not save players’ gold — it only loads it.


Player.UserId

The below example would print the UserId of every user who entered a game.


Met the Creator Badge

The following code sample gives an example of a ‘met the creator’ badge system. This script will award a specified badge (BADGE_ID) to anyone who is in a server at the same time as the user associated with OWNER_ID.