i am making a script that ensures that player leaderstats value do not go beyond a certain point and if it does it resets the value this is my script it works sometimes and sometimes don't
game.Players.PlayerAdded:Connect(function(player)
local function checks()
if player.leaderstats.Weight.Value > player.Capacity.Value then
player.leaderstats.Weight.Value = player.Capacity.Value
end
end
while true do
checks()
wait(0.1)
checks()
wait(0.1)
end
end)
sometimes i even get a error saying leaderstats is not a valid member of player please help

1 comment
you should add a WaitForChild to see if it helps, add this into the playeradded checks function: local leaderstatwait = player:WaitForChild("leaderstats")