How to put the Set User Thumbnail Async in a custom playerList?

Well, I have a problem and it is that I want to make that in the custom playerlist that I made, the GetUserThumbnailAsync of each player that is in the game can be put so that in their player Frame, their avatar image appears. Although the following script seems to work, the GetUserThumbnailAsync does not work and I don’t know what to do

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local function temp(player)
	local Players = game:GetService("Players")
	
	local UserId = player.UserId
	local thumbType = Enum.ThumbnailType.HeadShot
	local thumbSize = Enum.ThumbnailSize.Size420x420
	local content, isReady = Players:GetUserThumbnailAsync(UserId, thumbType, thumbSize)
	
	local Template = ReplicatedStorage:WaitForChild("Templates"):WaitForChild("TemplatePlayerList"):Clone()
	Template.Parent = script.Parent:WaitForChild("ScrollingFrame")
	Template.Name = player.Name
	Template:FindFirstChild("PlayerName").Text = player.Name
	Template:FindFirstChild("PlayerImage").Image = content
	Template.Visible = true
end

game.Players.PlayerAdded:Connect(function(plr)
	temp(plr)
end)

for _, players in pairs (game.Players:GetChildren()) do
	temp(players)
end

game.Players.PlayerRemoving:Connect(function(plr)
	for i, v in pairs (script.Parent:FindFirstChild("ScrollingFrame"):GetChildren()) do
		if v.Name and plr.Name then
			v:remove()
		end
	end
end)
1 Like

The first thing you should do is debug your code by checking your console for errors (F9 or View → Output). If your code isn’t working then this should be the first place you check. If your code is not throwing errors then the next thing you should do is employ basic debugging such as printing out the values of the variables you’re working with (e.g. content and isReady).

A forum thread usually carries the implication that you’ve exhausted debugging and attempting to fix this problem or you’re turning to other developers for input which then in that case you should supply as much information as possible, leading back to the need to debug/check your console first before doing anything when experiencing unexpected behaviour with your code. We can’t quite help you if the only context you’ve provided is “X function doesn’t work”. It’s not descriptive enough.

Well, if it works but does not give the image of the player

GetUserThumbnailAsync is a web call so it’s not guaranteed to return an image nor one that’s actually able to be used. This is why you need to employ basic debugging. You can print out the UserId, content and isReady variables to see what they’re showing and work around that.

Speaking of isReady, there’s a reason that’s returned as well and it’s to determine if the image can actually be used in experiences. If isReady is false then you’re probably not going to want to directly use the image returned but instead use a placeholder image.

I already tried the “userId” thing and also the “content” thing. In userId it simply comes out the ID where the image link should be but it does not give anything, in content if it comes out as if it came out image but it does not give it.

Don’t know what circumstances you’re working with, but your code works fine for me. Didn’t take that much effort to create a repro file either.

GetUserThumbnailAsyncRepro.rbxl (36.7 KB)

Works for me.

I don’t see any reason why this wouldn’t work. You could try adjusting the thumbnail size; I’m sure your UI doesn’t need 420x420 avatar headshots.

It could just be that the thumbnail isn’t ready when you’re trying to use it, but you’ve not setup any kind of loop or event to wait until it is ready. You’re making assumptions that the thumbnail is ready straight away.

You’ve created a variable to store the value of isReady, but never actually used that information. This could be your problem.


I also noticed this line towards the bottom, when a player leaves the game. This is actually just going to delete everything in the list.

I think what you meant to put was:

if v.Name == plr.Name then

Your current code is basically checking that v.Name ~= nil and plr.Name ~= nil, which will always evaluate to true in this scenario. You could also probably break out of the loop once your condition is met in order to prevent any further unnecessary processing.


I’d also recommend cleaning your code up a bit if you get the chance, too. You’ve made references to services directly when you should be using :GetService(), variables in the wrong scope, and are using deprecated methods (:Destroy() is preferred over :remove()).

1 Like

well, I don’t know if it’s a roblox studio bug but when I enter with 2 players, they don’t get their character image. for this I used the test mode and with that mode I got involved with two players and in neither one gave me an image