Is it possible to get the player's ID in a script? And not in a LocalScript?

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)

image

reminders:

  1. localplayer cant be accessed from server side
  2. anything changed in the client side wont be replicated or seen by other players

tldu what do you want to accomplish here

That is why I want to do it in a script, because in Local, only the player can see it.

I am trying to make it so that everybody knows that that PC is occupied by a player by seeing that there is another player’s icon.

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.

Hope this helps

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)

I don’t want just a certain player, any player can come and grab the PC and the player’s Icon will appear on the bill.

@OmqFroko in short if you want to get someone’s userid use Player.UserId (Player is an instance from game.Players)

Player.UserID isnt only functional on LocalScript?

Well, in that case you just need to change the Username-variable accordingly.

no. it’s functional in both sides

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.