Image Label not displaying avatars headshot

I have a script to show the top 3 players with the most KOs at the end of the game and along with that it shows their avatars headshot image, in this script it’s setting the name of the player and amount of KOs but its not setting the image label to the players avatar headshot.

Script

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RoundService = ReplicatedStorage:WaitForChild("RoundService")
local TopPlayersEvent = ReplicatedStorage:WaitForChild("TopPlayersEvent")
local roundEndedEvent = RoundService:WaitForChild("RoundEnded")

local TopPlayersGui = script.Parent

local function updateTopPlayersGui(topPlayers)
	for i, playerInfo in ipairs(topPlayers) do
		local frame = TopPlayersGui:FindFirstChild("PlayerFrame"..i)
		if frame then
			local nameLabel = frame:FindFirstChild("PlayerNameLabel")
			local koCountLabel = frame:FindFirstChild("KOCounterLabel")
			local imageLabel = frame:FindFirstChild("AvatarImageLabel")

			if nameLabel and koCountLabel and imageLabel then
				nameLabel.Text = playerInfo.Player.Name
				koCountLabel.Text = "KOs: " .. playerInfo.KOCounter

				local userId = playerInfo.Player.UserId
				local thumbnailUrl = Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
				imageLabel.Image = thumbnailUrl
			end
		end
	end
end

local function onRoundEnd()
	TopPlayersGui.Enabled = true
	wait(5)
	TopPlayersGui.Enabled = false
end

TopPlayersEvent.OnClientEvent:Connect(updateTopPlayersGui)
roundEndedEvent.OnClientEvent:Connect(onRoundEnd)
2 Likes

Check that your conditionals/if statements are actually being met first. Try printing something random after every if statement to see if it’s getting past that.

I’d also test just to see if TopPlayersEvent.OnClientEvent:Connect(updateTopPlayersGui) is actually working/passing the correct args through just to be on the safe side.

:Connect(function(topPlayers)
   updateTopPlayersGui(topPlayers)
end)

I’m pretty sure everything is passing through fine cause it gets the players KOs and name and I printed the “thumbnailUrl” and got this:

rbxthumb://type=AvatarHeadShot&id=-1&w=100&h=100 - Client - LocalScript:24

(the “-1” id the the id of player 1 in the local server test)

1 Like

That’s weird. Is the Image’s Visible property enabled? Let me just check how we did this and compare, hold up!

yes it is, but the “Image” property is empty.

1 Like

What prints when you print topPlayers? Is it possible that the UserId you’re putting in :GetUserThumbnailAsync is incorrectly indexed? Your method is correct so the only reason I can see it not updating the image is if there’s an incorrect argument to :GetUserThumbnailAsync

I printed the userIds first and it was correct and then I tested with 2 players and printing topPlayers gave me this:

06:34:49.149 ▼ {
[1] = ▼ {
[“KOCounter”] = 2,
[“Player”] = Player1
},
[2] = ▼ {
[“KOCounter”] = 0,
[“Player”] = Player2
}
} - Client -

I guess what I’d maybe do is “tostring()” the ‘Player’, assuming it’s just the player Instance which would always be the player’s name and then use GetUserIdFromNameAsync to create a separate variable and pass that through as the ID?

1 Like

I don’t know why I didnt think of this before but I just found the problem its cause I was testing in local server and the ids were -1 and -2 and not a actual player id.

1 Like

Ooh! I was thinking that might’ve been something to note but I also thought perhaps Roblox would’ve had something in place for situations like this. Glad it’s resolved!

1 Like

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