How to get a players icon with my script?

So, I have a sign that shows the last winner of the last round of my game. I have looked at multiple ways to get a player’s icon but it won’t work with the position my script is in and how I am getting the winner’s information.

I have a StringValue in replicated storage that is named “Winner”. That is how I am storing the player’s name and I have an object that they have to touch to win. The part adds a win to their ‘Wins’ leaderstat. So I have gotten the character but in the server script under the part. I don’t know if that is useful but I hope it is possible to get the player’s icon/face image.

Sign:


Explorer:
image

Edit: I tried doing it from the part that you touch itself. I keep getting errors about the UserId. Does anyone know how I would fix this?

Script:

local npc = script.Parent
local winner = game.ReplicatedStorage.Winner
local Players = game:GetService("Players")
local db = true

npc.Chicken.MeshPart.Touched:Connect(function(part)
	if db == true then
		db = false
		local h = part.Parent:findFirstChild("Humanoid")
		if (h~=nil) then
			player = game.Players:FindFirstChild(h.Parent.Name)
			if (player~=nil) then
				local stats = player:findFirstChild("leaderstats")
				if (stats~=nil) then
					local Score = stats:findFirstChild("Wins")
					if (Score~=nil) then
						Score.Value += 1
					end
				end
			end
		end
		winner.Value = tostring(player)
		
		-- Fetch the thumbnail
		local userId = player.UserId
		local thumbType = Enum.ThumbnailType.HeadShot
		local thumbSize = Enum.ThumbnailSize.Size420x420
		local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
		game.Workspace.WinnerSign.Sign.SurfaceGui.PlayerPicture.Image = content
		
		game.ReplicatedStorage.ChickenStatus = false
		npc.Humanoid.Health = 0
		task.wait(1)
		npc:Destroy()
	end
end)
1 Like

Something like this should work,

local Players = game:GetService("Players")
local player = Players.LocalPlayer

-- Fetch the thumbnail
local userId = player.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)

-- Set the ImageLabel's content to the user thumbnail
local imageLabel = script.Parent
imageLabel.Image = content
imageLabel.Size = UDim2.new(0, 420, 0, 420)

How would I incorporate it into my situation? I am not using a local script and I am not making it with their own face. It’s the face of the winner. I have tried using this script and modifying it but I can’t figure it out.

local players = game:GetService("Players")
local replicated = game:GetService("ReplicatedStorage")
local winner = replicated.Winner
local status = replicated.ChickenStatus

local npc = script.Parent
local chicken = npc.Chicken
local root = chicken.MeshPart

local winnerSign = workspace.WinnerSign
local sign = winnerSign.Sign
local gui = sign.SurfaceGui
local image = gui.PlayerPicture

local debounce = false

root.Touched:Connect(function(part)
	if debounce then return end
	local model = part:FindFirstAncestorOfClass("Model")
	if model then
		local player = players:GetPlayerFromCharacter(model)
		if player then
			debounce = true
			player.leaderstats.Wins.Value += 1		
			winner.Value = player.Name

			local content, isReady = players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
			if not isReady then
				task.wait(5)
			end
			
			image.Image = content
			status.Value = false
			task.wait(3)
			npc:Destroy()
			debounce = false
		end
	end
end)