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)
01 | while 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 ) |
20 | end |
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:
1 | for i = 1 , 60 do |
2 | wait( 1 ) |
3 | game.Players.LocalPlayer.leaderstats.TimerZ.Value = i |
4 | end |
Let's break it down in english.
1 | Starting at 1 , and ending at 60 , do this: |
2 | Wait 1 second |
3 | Display the number we are at |
4 | restart until the number is 60 |
We can reverse this by doing the following:
1 | for i = 60 , 1 , - 1 do |
2 | wait( 1 ) |
3 | game.Players.LocalPlayer.leaderstats.TimerZ.Value = i |
4 | end |
As short as possible:
1 | 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.