Beginner scripter trying to make a script that adds to a Variable stored inside of a leaderstats folder. The script works perfectly for about 10-20 touches then gives off this error: attempt to index nil with 'leaderstats'.
Any help appreciated, thanks.
debounce = false script.Parent.Touched:Connect(function(hit) if not debounce then debounce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent); player.leaderstats.Height.Value = player.leaderstats.Height.Value + 10 wait(1) debounce = false end end)
Make sure whatever touches it is a player
debounce = false script.Parent.Touched:Connect(function(hit) if not debounce then debounce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent); if player then player.leaderstats.Height.Value = player.leaderstats.Height.Value + 10 end wait(1) debounce = false end end)