Type Index Pages
- BillboardGui
- Frame
- Hint
- ImageButton
- ImageLabel
- PlayerGui
- ScreenGui
- ScrollingFrame
- StarterGui
- SurfaceGui
- TextBox
- TextButton
- TextLabel
- UIAspectRatioConstraint
- UIGradient
- UIGridLayout
- UIListLayout
- UIPadding
- UIPageLayout
- UIScale
- UISizeConstraint
- UITableLayout
- UITextSizeConstraint
- VideoFrame
- ViewportFrame
- ChangeHistoryService
- CoreGui
- DataModelSession
- DockWidgetPluginGui
- MultipleDocumentInterfaceInstance
- Plugin
- PluginAction
- PluginGui
- PluginGuiService
- PluginManager
- PluginMenu
- PluginMouse
- PluginToolbar
- PluginToolbarButton
- QWidgetPluginGui
- Selection
- StandalonePluginScripts
- StatsItem
- StudioService
- StudioTheme
No results found!
-
Instance
- GameSettings
- DebugSettings
- BodyMover
- WeldConstraint
- HttpRbxApiService
- NotificationService
- Translator
- Lighting
- Beam
- GuiService
- UserInputService
- Studio
- Plugin
- HttpService
- Mouse
- BindableEvent
- RunService
- Pages
- Humanoid
- TestService
- PathfindingService
- Chat
- NetworkPeer
- Feature
- CharacterAppearance
- Constraint
- NetworkReplicator
- JointInstance
- Light
- BasePlayerGui
- AnalyticsService
- NetworkMarker
- BinaryStringValue
- FlyweightService
- Geometry
- LoginService
- InstancePacketCache
- ThirdPartyUserService
- TouchInputService
- RuntimeScriptService
- GuidRegistryService
- PartOperationAsset
- DialogChoice
- PhysicsService
- AdService
- TextService
- MarketplaceService
- TeleportService
- Accoutrement
- GamePassService
- AssetService
- InsertService
- PointsService
- ChangeHistoryService
- ServerScriptService
- JointsService
- LogService
- InputObject
- Toolbar
- LuaSettings
- RenderSettings
- AnimationTrack
- PhysicsSettings
- NetworkSettings
- CFrameValue
- Animation
- Color3Value
- BoolValue
- BrickColorValue
- Vector3Value
- AnimationController
- BindableFunction
- Button
- Trail
- LocalizationTable
- LocalizationService
- DebuggerBreakpoint
- DebuggerWatch
- ScriptDebugger
- Animator
- Attachment
- RemoteFunction
- RemoteEvent
- PluginManager
- Camera
- Stats
- Sky
- StarterPlayer
- Dragger
- TerrainRegion
- Path
- TextFilterResult
- Dialog
- StatsItem
- GoogleAnalyticsConfiguration
- ScriptContext
- ControllerService
- CacheableContentProvider
- ReflectionMetadataClasses
- ReflectionMetadataEnums
- DebuggerManager
- GuiBase
- UIBase
- LuaSourceContainer
- GuiItem
- DataModelMesh
- ServiceProvider
- ReflectionMetadataItem
- PostEffect
- PhysicsPacketCache
- TouchTransmitter
- RobloxReplicatedStorage
- Visit
- LuaWebService
- ScriptService
- FlagStandService
- VirtualUser
- SpawnerService
- TimerService
- CookiesService
- Team
- GroupService
- StarterGear
- Message
- PlayerScripts
- Configuration
- ContentProvider
- CollectionService
- Debris
- ReplicatedFirst
- ServerStorage
- ReplicatedStorage
- Folder
- TweenService
- Players
- ContextActionService
- StarterPlayerScripts
- SoundService
- KeyframeSequenceProvider
- VRService
- PluginGuiService
- Player
- Teams
- Pose
- Keyframe
- KeyframeSequence
- IntConstrainedValue
- DoubleConstrainedValue
- ForceField
- RayValue
- Fire
- Smoke
- Sparkles
- ParticleEmitter
- IntValue
- StringValue
- NumberValue
- Explosion
- ObjectValue
- SoundGroup
- UserGameSettings
- ClickDetector
- Sound
- Selection
- BadgeService
- TaskScheduler
- GlobalDataStore
- DataStoreService
- CustomEvent
- CustomEventReceiver
- VirtualInputManager
- FunctionalTest
- TweenBase
- SoundEffect
- ReflectionMetadataEvents
- ClusterPacketCache
- PVInstance
- FaceInstance
- Controller
- ReflectionMetadataCallbacks
- ReflectionMetadataFunctions
- ReflectionMetadataYieldFunctions
- ReflectionMetadataProperties
- ReflectionMetadata
- AdvancedDragger
- HapticService
- FriendService
- GamepadService
No Result Found !!!
UserId
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
local player = game:GetService("Players"):GetPlayerByUserId(1) if player then print("Player with userId 1 is in this server! Their name is: " .. player.Name) else print("Player with userId 1 is not in this server!") end
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.
local Players = game:GetService("Players") local goldDataStore = game:GetService("DataStoreService"):GetDataStore("Gold") local STARTING_GOLD = 100 local function onPlayerAdded(player) local playerKey = "Player_" .. player.UserId local leaderstats = Instance.new("IntValue") leaderstats.Name = "leaderstats" local gold = Instance.new("IntValue", leaderstats) gold.Name = "Gold" local myGold local success, err = pcall(function() myGold = goldDataStore:GetAsync(playerKey) or STARTING_GOLD end) if success then gold.Value = myGold else -- Failed to retrieve data end leaderstats.Parent = player end for _, player in pairs(Players:GetPlayers()) do onPlayerAdded(player) end Players.PlayerAdded:Connect(onPlayerAdded)
Player.UserId
The below example would print the UserId of every user who entered a game.
game.Players.PlayerAdded:Connect(function(player) print(player.UserId) end)
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.
local BadgeService = game:GetService("BadgeService") local Players = game:GetService("Players") -- change these local OWNER_ID = 212423 -- can use game.CreatorId for published places local BADGE_ID = 1 local ownerInGame = false local function playerAdded(newPlayer) if newPlayer.UserId == OWNER_ID then -- if new player is the owner, set ownerInGame to true and give everyone the badge ownerInGame = true for _, player in pairs(Players:GetPlayers()) do -- don't award the owner if player ~= newPlayer then BadgeService:AwardBadge(player.UserId, BADGE_ID) end end elseif ownerInGame then -- if the owner is in the game, award the badge BadgeService:AwardBadge(newPlayer.UserId, BADGE_ID) end end local function playerRemoving(oldPlayer) if oldPlayer.UserId == OWNER_ID then -- set ownerInGame to false ownerInGame = false end end -- listen for players joining and leaving Players.PlayerAdded:Connect(playerAdded) Players.PlayerRemoving:Connect(playerRemoving) -- fire playerAdded for existing players for _, player in pairs(Players:GetPlayers()) do playerAdded(player) end
How this site use cookies
This Platform uses cookies to offer you a better experience, to personalize content, to provide social media features and to analyse the traffic on our site. For further information, including information on how to prevent or manage the use of cookies on this Platform, please refer to our Privacy and Cookie Policy.