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

How could I shorten this script down to make it easier?

Asked by
cboyce1 40
9 years ago

I want to make a countdown script, but I think it's going to take me over an hour to finish. How could I shorten this?

while true do

script.Parent.Text = "7:00"
wait(1)

script.Parent.Text = "6:59"
wait(1)

script.Parent.Text = "6:58"
wait(1)

-- Right down to 0:00

Thanks for your help :)

1 answer

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

You can use a for loop. It's pretty awesome.

NumberOfSeconds = 420

for i = NumberOfSeconds, 0, -1 do
    script.Parent.Text = i
    wait(1)
end

For every second, the text property will display the current number of seconds.

You can also add some math stuff so it would display "7:00" instead of "420."

0
Good thinking :) thanks :D cboyce1 40 — 9y
0
Wait, I just tried it, I need a countdown. It's going up, not down. How can I edit the script to solve that? cboyce1 40 — 9y
0
Updated; all I've done is make the initial variable set to the number of seconds, and the final variable to 0. I have it go down by -1. Redbullusa 1580 — 9y
Ad

Answer this question