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)
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.
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 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?
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.
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!