Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to count time down from a leaderstats?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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)

01while true do
02        game.Players.LocalPlayer.leaderstats.TimerZ.Value = "25"
03        wait(1)
04        game.Players.LocalPlayer.leaderstats.TimerZ.Value = "24"
05        wait(1)
06        game.Players.LocalPlayer.leaderstats.TimerZ.Value = "23"
07        wait(1)
08        game.Players.LocalPlayer.leaderstats.TimerZ.Value = "22"
09        wait(1)
10        game.Players.LocalPlayer.leaderstats.TimerZ.Value = "21"
11        wait(1)
12        game.Players.LocalPlayer.leaderstats.TimerZ.Value = "20"
13        wait(1)
14        game.Players.LocalPlayer.leaderstats.TimerZ.Value = "19"
15        wait(1)
16        game.Players.LocalPlayer.leaderstats.TimerZ.Value = "18"
17        wait(1)
18        game.Players.LocalPlayer.leaderstats.TimerZ.Value = "17"
19        wait(1)
20end

2 answers

Log in to vote
7
Answered by 9 years ago

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:

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

Let's break it down in english.

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

We can reverse this by doing the following:

1for i = 60, 1, -1 do
2    wait(1)
3    game.Players.LocalPlayer.leaderstats.TimerZ.Value = i
4end
Ad
Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

As short as possible:

1for 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.

0
replaced math.huge with 1/0 to reduce by 6 characters. 1waffle1 2908 — 9y

Answer this question