I cannot retrieve the playerUserId by script

Can someone pls help me review this code
local debounce = false
local TouchedPart = script.Parent

local Players = game:GetService(“Players”)

TouchedPart.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)

local playerUI = Players:GetNameFromUserIdAsync(player.Name)


if player and debounce == false then
	debounce = true
	
	local PlayerImage = TouchedPart.PlayerImageGui:Clone()
	PlayerImage.Parent = TouchedPart
	PlayerImage.ImageLabel.Image = Players:GetUserThumbnailAsync(playerUI, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
	
	
	wait(1)
	debounce = false
end

end)

I cannot get the PlayerUserId though

Hey ogether123!

You didn’t receive the player userid because playerUi will always return nil. This is because your doing GetNameFromUserIdAsync. Instead you should try doing this:

local playerUi = player.UserId

Yes.It did work,Thanks for helping me

When you have code that isn’t working, #help-and-feedback:scripting-support would be more applicable. Additionally, when a reply is the solution you needed, please make sure to mark it as such.


This is my game design,there are still some parts that still need to be fixed