Hello, I am trying to make a system that changes the player’s hat once they reach a certain amount of points. The problem comes when I run it and reach the needed points, it does nothing and doesn’t give me an error in the output. I can’t find anything that is wrong with the script so I am not sure what is causing the error to happen.
local Players = game:GetService("Players")
local function giveHat(plr)
local Humanoid = plr.Character:WaitForChild("Humanoid")
local shaggy = Instance.new("Accessory")
shaggy.Name = "Shaggy"
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Size = Vector3.new(1,1.6,1)
handle.Parent = shaggy
local faceFrontAttachment = Instance.new("Attachment")
faceFrontAttachment.Name = "HatAttachment"
faceFrontAttachment.Position = Vector3.new(0.12, 0.4, -0.07)
faceFrontAttachment.Parent = handle
local mesh = Instance.new("SpecialMesh")
mesh.Name = "Mesh"
mesh.Scale = Vector3.new(1.07, 1.07, 1.07)
mesh.MeshId = "rbxassetid://19999424"
mesh.TextureId = "rbxassetid://20571982"
mesh.Parent = handle
Humanoid:AddAccessory(shaggy)
end
local function checkPoints(plr, value)
if plr.leaderstats.Robux.Value >=25 then
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)
checkPoints(plr,plr.leaderstats.Robux.Value)
end)
Players.PlayerAdded:Connect(function(plr)
plr.leaderstats.Robux.Changed:Connect(function()
checkPoints(plr, plr.leaderstats.Robux)
end)