Hey everyone! So I’ve tried making a script to make an in-game timer to work until 8pm UTC on October 6th, 2019. My script is here:
local day = os.date("*t")["day"]
local month = os.date("*t")["month"]
local hour = os.date("*t")["hour"]
local minute = os.date("*t")["minute"]
local second = os.date("*t")["second"]
while true do
if day < endDay.day then
if hour < endDay.hour then
if minute < endDay.minute then
if second < endDay.second then
print(endDay.day - day .. ":" .. endDay.hour - hour .. ":" .. endDay.minute - minute .. ":" .. endDay.second - second)
end
end
end
end
wait(1)
end
The first problem is that the table that os.date returns doesn’t have “minute” or “second” fields. They’re actually “min” and “sec”.
It would probably be easier for you to compare if os.time() is over or equal to 1570392000 (Sunday, October 6, 2019 8:00:00 PM GMT). You can easily generate this number as well. Just google “unix epoch time converter” and it should be the first result.
local DateTable = os.date("!*t", os.time())
local day = DateTable.day
local month = DateTable.month
local hour = DateTable.hour
local minute = DateTable.min
local second = DateTable.sec
So I combined your strategies, and this is what I came up with.
local endDay = {month = 10, day = 5, hour = 8, min = 0, sec = 0}
local DateTable = os.date("!*t", os.time())
local day = DateTable.day
local month = DateTable.month
local hour = DateTable.hour
local minute = DateTable.min
local second = DateTable.sec
script.Day.Value = day
script.Hour.Value = hour
script.Minute.Value = minute
script.Second.Value = second
while true do
if day < endDay.day then
if hour < endDay.hour then
print(endDay.day - day .. ":" .. endDay.hour - hour .. ":" .. endDay.min - minute .. ":" .. endDay.sec - second)
end
end
wait(1)
end
You can subtract the os.time() number from 1570392000 (October 6th at 8 PM GMT) in order to get the number of seconds remaining. You can then do math in order to get the days, hours, minutes, and seconds remaining.
P.S. Is there a way to remove the decimal from a number? i.e. I have 5.503189, can I remove the 503189 (or however many seconds are left exactly) through code to just have 5?