Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to count time down from a leaderstats?

This is a little part of the script.

I need a counting down with leaderstats..

Is their a way to make it shorter? Bc its for my custom disaster script and then i need to do it for 60 seconds too (I need leaderstats)

while true do
		game.Players.LocalPlayer.leaderstats.TimerZ.Value = "25"
		wait(1)
		game.Players.LocalPlayer.leaderstats.TimerZ.Value = "24"
		wait(1)
		game.Players.LocalPlayer.leaderstats.TimerZ.Value = "23"
		wait(1)
		game.Players.LocalPlayer.leaderstats.TimerZ.Value = "22"
		wait(1)
		game.Players.LocalPlayer.leaderstats.TimerZ.Value = "21"
		wait(1)
		game.Players.LocalPlayer.leaderstats.TimerZ.Value = "20"
		wait(1)
		game.Players.LocalPlayer.leaderstats.TimerZ.Value = "19"
		wait(1)
		game.Players.LocalPlayer.leaderstats.TimerZ.Value = "18"
		wait(1)
		game.Players.LocalPlayer.leaderstats.TimerZ.Value = "17"
		wait(1)
end

2 answers

✓ Accepted answer

What you would need to look into is a

for statement.

Let's take a look at how we would use it in this sense:

for i = 1, 60 do
	wait(1)
	game.Players.LocalPlayer.leaderstats.TimerZ.Value = i
end

Let's break it down in english.

Starting at 1, and ending at 60, do this:
Wait 1 second
Display the number we are at
restart until the number is 60

We can reverse this by doing the following:

for i = 60, 1, -1 do
	wait(1)
	game.Players.LocalPlayer.leaderstats.TimerZ.Value = i
end

As short as possible:

for i=0,1/0 do game.Players.LocalPlayer.leaderstats.TimerZ.Value=60-i%61 wait(1)end

I changed the while loop into an infinite for loop and set the value to 60-i%61 so it counts down from 60 to 0 and repeats.

1 comment

0

replaced math.huge with 1/0 to reduce by 6 characters.

This discussion is preserved as it was. New answers, comments, and votes are closed.