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

How do I make a timer?

Asked by 9 years ago

I am trying to make a timer that counts down from 60. This script works perfectly but apparently it crowds up my script too much. Is there a shorter form of this timer?

local msg = Instance.new("Hint")
    msg.Parent = nil
    msg.Parent = game.Workspace
    msg.Text = "Intermission: 60"
    wait(1)
    msg.Text = "Intermission: 59"
    wait(1)
    msg.Text = "Intermission: 58"
    wait(1)
    msg.Text = "Intermission: 57"
    wait(1)
    msg.Text = "Intermission: 56"
    wait(1)
    msg.Text = "Intermission: 55"
    wait(1)
    msg.Text = "Intermission: 54"
    wait(1)
    msg.Text = "Intermission: 53"
    wait(1)
    msg.Text = "Intermission: 52"
    wait(1)
    msg.Text = "Intermission: 51"
    wait(1)
    msg.Text = "Intermission: 50"
    wait(1)
    msg.Text = "Intermission: 49"
    wait(1)
    msg.Text = "Intermission: 48"
    wait(1)
    msg.Text = "Intermission: 47"
    wait(1)
    msg.Text = "Intermission: 46"
    wait(1)
    msg.Text = "Intermission: 45"
    wait(1)
    msg.Text = "Intermission: 44"
    wait(1)
    msg.Text = "Intermission: 43"
    wait(1)
    msg.Text = "Intermission: 42"
    wait(1)
    msg.Text = "Intermission: 41"
    wait(1)
    msg.Text = "Intermission: 40"
    wait(1)
    msg.Text = "Intermission: 39"
    wait(1)
    msg.Text = "Intermission: 38"
    wait(1)
    msg.Text = "Intermission: 37"
    wait(1)
    msg.Text = "Intermission: 36"
    wait(1)
    msg.Text = "Intermission: 35"
    wait(1)
    msg.Text = "Intermission: 34"
    wait(1)
    msg.Text = "Intermission: 33"
    wait(1)
    msg.Text = "Intermission: 32"
    wait(1)
    msg.Text = "Intermission: 31"
    wait(1)
    msg.Text = "Intermission: 30"
    wait(1)
    msg.Text = "Intermission: 29"
    wait(1)
    msg.Text = "Intermission: 28"
    wait(1)
    msg.Text = "Intermission: 27"
    wait(1)
    msg.Text = "Intermission: 26"
    wait(1)
    msg.Text = "Intermission: 25"
    wait(1)
    msg.Text = "Intermission: 24"
    wait(1)
    msg.Text = "Intermission: 23"
    wait(1)
    msg.Text = "Intermission: 22"
    wait(1)
    msg.Text = "Intermission: 21"
    wait(1)
    msg.Text = "Intermission: 20"
    wait(1)
    msg.Text = "Intermission: 19"
    wait(1)
    msg.Text = "Intermission: 18"
    wait(1)
    msg.Text = "Intermission: 17"
    wait(1)
    msg.Text = "Intermission: 16"
    wait(1)
    msg.Text = "Intermission: 15"
    wait(1)
    msg.Text = "Intermission: 14"
    wait(1)
    msg.Text = "Intermission: 13"
    wait(1)
    msg.Text = "Intermission: 12"
    wait(1)
    msg.Text = "Intermission: 11"
    wait(1)
    msg.Text = "Intermission: 10"
    wait(1)
    msg.Text = "Intermission: 9"
    wait(1)
    msg.Text = "Intermission: 8"
    wait(1)
    msg.Text = "Intermission: 7"
    wait(1)
    msg.Text = "Intermission: 6"
    wait(1)
    msg.Text = "Intermission: 5"
    wait(1)
    msg.Text = "Intermission: 4"
    wait(1)
    msg.Text = "Intermission: 3"
    wait(1)
    msg.Text = "Intermission: 2"
    wait(1)
    msg.Text = "Intermission: 1"
    wait(1)
    msg.Text = "Intermission: 0"
    wait(1)

3 answers

Log in to vote
2
Answered by 9 years ago

You can use a for loop to decrease the time efficiently. This script will probably work correctly but you may need to adjust it a little to make it work.

local msg = Instance.new("Hint")
msg.Parent = nil
msg.Parent = game.Workspace
for i = 0, 60 do
    msg.Text = "Intermission: ".. 60 - i
end
0
msg.Parent = nil on line 2 was un needed:P Goulstem 8144 — 9y
1
also add a wait(1) inside of the for i=0,60 do so it doesn't just go through it in an instant blowup999 659 — 9y
1
Yes, I forgot about that blowup. Also Goulstem, that would also be correct. FearMeIAmLag 1161 — 9y
Ad
Log in to vote
2
Answered by 9 years ago

Your script is perfect! You only lack efficiency. Would you rather have a 125 line script or a 6 line script. Try out this script:

local msg = Instance.new("Hint")
msg.Parent = game.Workspace
for i = 0, 60 do
    msg.Text = "Intermission: ".. 60 - i
        wait(1)
end
Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Well, your script should work perfectly fine. But efficiency-wise it suffers. To fix up your script then what you can do is use a For loop to go through all the numbers, this way then each time the for loop iterates, we can set the text to the current number(:

local msg = Instance.new("Hint",game.Workspace)

for i = 60,0,-1 do --Start, end, increment
    msg.Text = "Intermission: "..tostring(i) --Use tostring so you can concatenate the 'i' value.
end

Answer this question