I am trying to make a player icon in a billboard gui where everyone can see the player icon but for that, I need the player ID, I know how to get the ID but it only works in LocalScript and I was wondering if there is another way to get it but in the script and not in a LocalScript.
local BillGui = script.Parent.Parent.Parent.Up.BillboardGui
local Icon = BillGui.Icon
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = game.Players:GetUserThumbnailAsync(ID, thumbType, thumbSize)
You can use the game.Players:GetUserIdFromNameAsync() method to get the UserId of a player.
Keep in mind, roblox may give you an error if the user has been deleted. In that case it’s also good practice to wrap it into a pcall.
Example:
local Username = "DosenSuppe2_0"
local UserId
pcall(function()
UserId = game.Players:GetUserIdFromNameAsync(Username)
end)
print(UserId)
There are many ways to construct the pcall. But this is just for showing you.
local BillGui = script.Parent.Parent.Parent.Up.BillboardGui
local Icon = BillGui.Icon
function change(player)
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = game.Players:GetUserThumbnailAsync(player.UserId, thumbType, thumbSize)
end
-- just an example. wont work unless you change it
local players = game:GetService("Players")
change(players.Someone)
@OmqFroko in short if you want to get someone’s userid use Player.UserId (Player is an instance from game.Players)