Attempt to index nil with 'UserId'

Hello! I tried to fix it several times but I have no idea how to fix it

Problem :
I tried to get roblox profile to imagelabel but it won’t work

Code :


local groupID = 13238125 -- ไอดีกลุ่ม
local Player = game.Players.LocalPlayer

game.Players.PlayerAdded:Connect(function(player)
	local groupRank = player:GetRoleInGroup(groupID)
	local clone = script:FindFirstChild("Nametag"):Clone()
	clone.Parent = game.Workspace:WaitForChild(player.Name).Head
	clone.Bg.Ing.Username.Text = player.Name
	clone.Bg.Ing.Group.Text = groupRank
	clone.Bg.pf.Image = game.Players:GetUserThumbnailAsync(Player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
	player.CharacterAdded:Connect(function()
		local groupRank = player:GetRoleInGroup(groupID)
		local clone = script:FindFirstChild("Nametag"):Clone()
		clone.Parent = game.Workspace:WaitForChild(player.Name).Head
		clone.Bg.Ing.Username.Text = player.Name
		clone.Bg.Ing.Group.Text = groupRank
		clone.Bg.pf.Image = game.Players:GetUserThumbnailAsync(Player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
	end)


end)

Output :

  01:22:43.474  ServerScriptService.InsRankHandler:13: attempt to index nil with 'UserId'  -  Server - InsRankHandler:13

Thank you very much if you can solve the problem for me! :grin:

Sorry for bad english >:

1 Like

Is this in a server script? If it is then .LocalPlayer cant be accessed, it can only be accessed in local scripts.

1 Like

try in a local script if this is a server script

1 Like