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

How do I make a script that makes a timer count down from 5?

Asked by 7 years ago

I am making a mannequin challenge game and I can't figure out how to make it count down from 5 and then say "STAY STILL!" and then if they keep moving for over (0.25) seconds they respawn back at the lobby. I need help on how to make a script that makes a timer that counts down

4 answers

Log in to vote
0
Answered by 7 years ago

Here you go my friend! Just create a new script and paste this in there and you should be good to go! Let me know if you have any problems with the code.

local Time = 5

function countDown()
    h = Instance.new("Hint")
    h.Parent = game.Workspace
    wait(2)
    h.Text = "Mannequin Challenge in..."
    wait(1)
    for i = Time,1,-1 do
        h.Text = i
        wait(1)
    end
    h.Text = "Stay Still!"
    wait(2)
    h:Destroy()
end

countDown()

0
If you could, please leave an up vote. Thanks! TickTockTheory 106 — 7y
0
Thanks! Helped a lot! warmmonster6 -3 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Hello,
To count down, you could use the following code:

wait(5)
print("Five seconds have passed")

Hope this helps you in the long run.

Log in to vote
0
Answered by 7 years ago

Greetings. If you wish to display how many seconds left for the countdown timer, you may use this simple method:

local Time = 5
while true do
    print(Time, " seconds left")-- Change this line to how you want the remaining time to be displayed.
    wait(1)
    if Time == 0 then
        print("Time is up!")-- Same with this line.
        break
    else
    Time = Time - 1
    end
end

You can replace the "Time" variable with how long you want until players have to freeze and replace the two print statements with however you want to display the remaining time.

0
That is a bunch of unnecessary coding LOL thehybrid576 294 — 7y
0
Alright, let's see yours. Naughtyrobot 0 — 7y
0
it doesn't work for me warmmonster6 -3 — 7y
Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
7 years ago
Edited 5 years ago

Solution

What you're looking for is a for loop. They're rather easy, there are three parameters, starting point, ending point, and increment.

for i = 5, 0, -1 do --For 5 -1 ... until we reach 0 do print i.
    print(i)
end

Hopefully this answered your question, if it did hit the accept answer button. If you have any questions, leave them in the comments section down below this post.

Answer this question