GetUserThumbnailAsync not working for hit parent?

there is no error in output but idk why it isnt working

local imageLabel = Instance.new("ImageLabel")
imageLabel.Parent = script.Parent:WaitForChild("BillboardGui").Frame 

local function onPartTouched(hit)
	local character = hit.Parent 
	local humanoid = character:FindFirstChild("Humanoid")

	if humanoid then
		local player = game:GetService("Players"):GetPlayerFromCharacter(character)
		if player then
		local thumbnailUrl = game:GetService("Players"):GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420) -- 플레이어의 썸네일 URL을 가져옵니다.
		if thumbnailUrl then
			imageLabel.Image = thumbnailUrl
				imageLabel.Parent.Visible = true
			end
			end
	end
end

local part = script.Parent 
part.Touched:Connect(onPartTouched)

Try this:

local imageLabel = Instance.new("ImageLabel")
imageLabel.Parent = script.Parent:WaitForChild("BillboardGui").Frame 

local function onPartTouched(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
		local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

		if player then
			local thumbnailUrl

			local success, errormsg = pcall(function()
				 thumbnailUrl = game:GetService("Players"):GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
			end)

			if success then
				imageLabel.Image = thumbnailUrl
				imageLabel.Parent.Visible = true
			else
				error(errormsg)
			end
		end
	end
end

local part = script.Parent 
part.Touched:Connect(onPartTouched)

Explanation:

if hit.Parent:FindFirstChild("Humanoid") then
A lot of Parts will touch and fire the event, so you have to eliminate the possibilities of non-humanoid parts. This verification for humanoid will be more precise to find the player.

local success, errormsg = pcall(function()
Asynchronous functions, like GetUserThumbnailAsync or TeleportAsync are more safe to run in a pcall wrap, this will tell you what kind of issues happened. You can think of this like a Promise, a method that’s used to route alternatives when it fails.

1 Like

idk but same error keeps showing without any error in output (there is no image in imagelabel, just white image)

Okay, we will have to find the problem by using print. This code will tell you what will work and what doesn’t work, try it out and let me know what results you receive.

local imageLabel = Instance.new("ImageLabel")
imageLabel.Parent = script.Parent:WaitForChild("BillboardGui").Frame 

local function onPartTouched(hit)
    print("Part touched")
    if hit.Parent:FindFirstChild("Humanoid") then
		local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

		if player then
            print("Player found")
			local thumbnailUrl

			local success, errormsg = pcall(function()
				 thumbnailUrl = game:GetService("Players"):GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
			end)

			if success then
				imageLabel.Image = thumbnailUrl
				imageLabel.Parent.Visible = true
                print("Success")
			else
				error(errormsg)
			end
		end
	end
end

local part = script.Parent 
part.Touched:Connect(onPartTouched)
1 Like

it prints “Part Touched”, “Player Found”, and “Success”

Okay, then the issue could be your image object or billboard, because I tested this and it works for me. Please make sure that your image frame size is correct, your position is correct, and the size of everything else.

1 Like

try that:

local imageLabel = Instance.new("ImageLabel")
imageLabel.Parent = script.Parent:WaitForChild("BillboardGui").Frame
imageLabel.Size = UDim2.new(0, 100,0, 100)

local function onPartTouched(hit)
	local character = hit.Parent 
	local humanoid = character:FindFirstChild("Humanoid")

	if humanoid then
		local player = game:GetService("Players"):GetPlayerFromCharacter(character)
		if player then
		local thumbnailUrl = game:GetService("Players"):GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420) -- 플레이어의 썸네일 URL을 가져옵니다.
		if thumbnailUrl then
			imageLabel.Image = thumbnailUrl
				imageLabel.Parent.Visible = true
			end
			end
	end
end

local part = script.Parent 
part.Touched:Connect(onPartTouched)
1 Like

wow its working what was a problem?

The size wasnt defined lol so it didnt work

1 Like

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