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

What's wrong with this countdown to a specific date?

Asked by 4 years ago
Edited 4 years ago

I've been trying to get a countdown that counts down to a specific date with the days, hours, minutes, and seconds. I can't figure out how to get it. My current script is this:

local trackingDay = 31
local countdownDay = os.time({year=2019; month=10; day=trackingDay})
local secondsDiff = os.difftime(countdownDay,os.time())
local dateTable = os.date("*t",os.time())
local daysLeft = trackingDay - dateTable.day

local function toHMS(s)
    return ("i:i:i"):format(s/60^2, s/60%60, s%60) -- It says (%)02i but it doesn't show up here and only shows i
end

while wait(1) do
secondsDiff = os.difftime(countdownDay,os.time())
daysLeft = trackingDay - dateTable.day
script.Parent.Text = daysLeft .. ":" .. toHMS(secondsDiff)
end

Could anyone help? Thanks.

Answer this question