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)
script.Parent.MouseButton1Click:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:wait()
local hum = char.Humanoid
local Replicated = game:GetService("ReplicatedStorage")
local hat = Replicated:WaitForChild("TopHat"):Clone()
if plr.leaderstats.PopPoints.Value >= 2 then
hum:AddAccessory(hat)
else
print("PLAYER DOES NOT HAVE ENOUGH POINTS")
end
end)
fire to the server and from there, do Humanoid:AddAccessory
also @TwinPlayzDev is right, you should be using a local script for all guis, but instead of adding accessory directly from local, you have to fire to server the parameter hat and then addaccessory