Increase leaderstats by 1 every second

How would I increase the “speed” leaderstats of each player by 1 every single second? I think while loops are viable methods but also know they are to be avoided at all times due to performance issues. I know RunService has a HeartBeat method but it runs way too quickly. I need the leaderstats to go up by 1 every second, not every frame. Ideas?

Very simple script:

game.Players.PlayerAdded:Connect(function(player)
	local speed = player:WaitForChild("leaderstats"):WaitForChild("Speed")
	speed.Value = speed.Value + 1
end)
1 Like

your “Very simple script” wouldn’t even work since it doesn’t create the leaderstats and speed value

when you say while loops should be avoided, i agree but that’s only when you’re looping through heavy code fast

a simple 1 second increment isn’t going to hurt

game.Players.PlayerAdded:Connect(function(Player)
  local Leaderstats = Instance.new("Folder", Player); Leaderstats.Name = "leaderstats"
  local Speed = Instance.new("NumberValue", Leaderstats); Speed.Name = "Speed"
  while wait(1) do
    Speed.Value += 1
  end
end)
1 Like

use a while loop and then add wait(1) at the end

The leaderstats is handled in a seperate script

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.