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

[solved] How would I make this timer work properly using math?

Asked by 3 years ago
Edited 3 years ago
while wait(1) do
    local Hours = math.floor((Time - os.time()) / 3600)
    local Minutes = math.floor(((Time - os.time()) / 60) / Hours)
    local Seconds = math.floor(Time - os.time() / Minutes)
end

I am trying to make a countdown that displays hours, minutes and seconds. But it doesn't work because my math is wrong somewhere. But I do not know where. How would I fix this?

Time is os.time 24 hours in the future, so i need to countdown.

2 answers

Log in to vote
0
Answered by 3 years ago

Your are correct, the maths is wrong. I'll provide a function i use to get hours, minutes and seconds

local function GetHMS(number)
    local hours = 0
    local minutes = 0
    local seconds = 0
    if number >= 3600 then
        repeat
            number = number - 3600
            hours = hours + 1
        until number < 3600
    end
    if number >= 60 then
        repeat
            number = number - 60
            minutes = minutes + 1
        until number < 60
    end
    seconds = number
    return {hours,minutes,seconds}
end

GetHMS(math.floor(Time - os.time()))
Ad
Log in to vote
0
Answered by 3 years ago

I figured it out myself,

while wait(1) do
    local Hours = math.floor((Time - os.time()) / 3600)
    local Minutes = math.floor((Time - os.time()) / 60) % 60 
    Timer.Text = Hours..":"..Minutes
end

Answer this question