You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
I would like to achieve a game day/night cycle that is based off the Eastern Time Zone (EST / EDT )
What is the issue?
The issue is as it is right now it is only doing the hours, however, I would like it to also have the minutes and seconds. I’d also like to display the current time on a GUI but that part is not necessary at this time.
What solutions have you tried so far?
I have not tried any as I don’t really understand this, I found this code on this post and I tried to understand the code but just can’t grasp it.
I put the code in a while loop so that it updates every 60 seconds / 1 minute however I’m not sure if this is the best way to do it!
while true do
local dateTime = DateTime.now()
local universalTime = dateTime:ToUniversalTime()
local estTime = universalTime.Hour - 5
game.Lighting.ClockTime = estTime
wait(60)
end
Please help if you can, any is appreciated.
Edit 1:
Changed cstTime to estTime to make the script a little more organized and understandable.
You could use HttpService to update the time every 60 seconds. Conveniently, there’s this free web API at worldclockapi.com/api/json/est/now which sends back JSON.
Oop, just found an error in the code you provided.
while true do
local dateTime = DateTime.now()
local universalTime = dateTime:ToUniversalTime()
universalTime.Hour -= 5
local estTime = DateTime.fromUniversalTime(universalTime)
game.Lighting.ClockTime = estTime:FormatUniversalTime("hh:mm:ss", "en-us")
print(game.Lighting.ClockTime)
wait(60)
end
ERROR:
ServerScriptService.TimeCycle:5: invalid argument #1 to 'fromUniversalTime' (number expected, got table)
Alright, no errors but by default, it sets to night when it’s almost 3 Pm, is there any solution to this?
This is the current code I have with the edits provided.
while true do
local dateTime = DateTime.now()
local universalTime = dateTime:ToUniversalTime()
universalTime.Hour -= 5
local estTime = DateTime.fromUniversalTime(universalTime.Year, universalTime.Month, universalTime.Day, universalTime.Hour, universalTime.Minute, universalTime.Second, universalTime.Millisecond)
game.Lighting.TimeOfDay = estTime:FormatUniversalTime("hh:mm:ss", "en-us")
wait(60)
end