Real Time Day/Night script

Hello :slightly_smiling_face:. I need help with coding a real time Day/Night script using San Antonio time.
Problem: I need Lua to find San Antonio time (CST/GMT-6) and then to match it in the Day/Night script.

I have tried tick(), however that gets the user time, which I don’t need.
Is it possible? If so, how would I approach it? Is it possible to pinpoint San Antonio time or would I have to do a whole timezone?
Thanks for reading.
imaxZulu832.

4 Likes

You can use os.time and os.date to get exact hour and minutes.

local t = os.time() - (6 * 3600) -- CST time (UTC minus 6 hours)
local d = os.date("!*t", t) -- Lua date table
local s = string.format("%02d:%02d:%02d", d.hour, d.min, d.sec) -- format into HH:MM:SS
print(s)
game.Lighting.TimeOfDay = s

Alternatively you could do:

local m = (d.hour * 60) + d.min + (d.sec / 60)
game.Lighting:SetMinutesAfterMidnight(m)

Reference

11 Likes