Putting a hat on a player

So I am trying to make it when a player clicks on a GUI box it equips a hat to them but only if they have the correct amount of pop points (like a rank) this is my code

Code

wantedhat = nil
script.Parent.MouseButton1Click:Connect(function()
if game.Players.LocalPlayer.leaderstats.PopPoints.Value >= 2 then

		local hum = character.Humanoid
		local ss = game:GetService("ReplicatedStorage")
		local hat = ss:WaitForChild("TopHat"):Clone()
		hum:AddAccessory(hat)
end

end)

1 Like

try this code

wantedhat = nil
script.Parent.MouseButton1Click:Connect(function()
if game.Players.LocalPlayer.leaderstats.PopPoints.Value <= 2 then 


		local hum = character.Humanoid
		local ss = game:GetService("ReplicatedStorage")
		local hat = ss:WaitForChild("TopHat"):Clone()
		hum:AddAccessory(hat)
end