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 8 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)

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

Log in to vote
7
Answered by 8 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:

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
Ad
Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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.

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

Answer this question