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

How do i make a countdown/up timer?

Asked by
3F1VE 257 Moderation Voter
4 years ago

How do i make a timer? Thats it.

0
pls help lol 3F1VE 257 — 4y

1 answer

Log in to vote
1
Answered by
stef0206 125
4 years ago

We don't make script at request on here, we ask questions about premade scripts. To do this, simply select an amount of seconds, let's say 100 for this example.

local Time = 100 -- What the timer should start at
local Goal = 0 -- What the goal is for the timer
local Interval = -1 -- How much it will decrease the timer every second. Change this to 1 if you want to count up.

-- Determine whether the loop counts up or down and start a loop
if Goal > Time then
    while Time < Goal do
        local Minutes = math.floor(Time / 60) -- Since time is amount of seconds the timer is on, and 1 minutes is 60 seconds we divide Time by 60. To avoid decimals we floor that number.
        local Seconds = Time - Minutes * 60 -- We see how many seconds are left after we take out the minutes.

        print(Minutes..':'..Seconds) -- Print this timer
        wait(1) -- Waits 1 second before the loop runs again
        Time = Time + Interval
    end
else
    while Time > Goal do
        local Minutes = math.floor(Time / 60) -- Since time is amount of seconds the timer is on, and 1 minutes is 60 seconds we divide Time by 60. To avoid decimals we floor that number.
        local Seconds = Time - Minutes * 60 -- We see how many seconds are left after we take out the minutes.

        print(Minutes..':'..Seconds) -- Print this timer
        wait(1) -- Waits 1 second before the loop runs again
        Time = Time + Interval
    end
end

You still need to add a way to display the timer yourself. Hope this helps. Keep what I said at the beginning of my post in mind!

Ad

Answer this question