Headshot Thumbnail of another player in game

I’ve got a snippet of my code where I’m creating an invitation system to other players in the game to pair up with another player. There is an ImageLabel as a child of inviteGui which I am hoping to make a headshot thumbnail of player’s avatar.

invitationEvent.OnClientEvent:Connect(function(player, targetPlayer)
	inviteGui.Enabled = true
	inviteGui.PairUpMessage.Text = (tostring(player).. " would like to pair up!")

	--other code for pressing accept / decline buttons here
end)

To make it clear, Player1 sends an invitation to Player2. a GUI for Player2 appears with a headshot thumbnail of Player1’s avatar with a message that “Player1 would like to pair up!”.

I’ve seen from searching the wiki and documentation that it’s advised to use Players:GetUserThumbnailAsync() but I’m unsure if this is applicable for my scenario, and if so how to use it here?

Any help would be greatly appreciated, thank you.

You could really either just format the URL address with the UserId or use GetUserThumbnailAsync(). The main difference is that in my experience, GetUserThumbnailAsync() needs to be pcalled and it also halts the script until the image is loaded (not sure if that is even true). I’d suggest you just use the URL version because it will load in at the same speed but not halt your script.

Example:

ImageLabel.Image = `rbxthumb://type=AvatarHeadShot&id={player.UserId}&w=420&h=420`

From my own experience, I’ve never encountered errors using Players:GetUserThumbnailAsync() so yeah, I’d recommend it. It is perfectly acceptable to use the return for ImageLabel.Image.

To use it:

local userId = 1220039795 --the player's UserId
local imageId = table.pack(game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size48x48))[1]

whateverImageLabel.Image = imageId

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