Connecting Game Time with IRL Time

I want to make a script for my game that does the following:

  1. Gets the time in a specific timezone (e.g. GMT+10)
  2. Starts a loop for a day and night cycle from that.

I know how to make a day and night cycle, but am unsure how to connect the server to an irl timezone at the beginning of server start.

Please help me!

1 Like

You would need to get a DateTime object which is DateTime.now()
To set this at the local time zone DateTime.now():ToLocalTime()
If you wanted to set a specific timezone you would need to +/- the offset to the UTC time.
There is a community tutorial here:
Timezones In Scripting - Resources / Community Tutorials - Developer Forum | Roblox
And for more information check this page
DateTime | Documentation - Roblox Creator Hub

use tick and convert it to the timezone, then set it to Lighting.ClockTime

local Lighting = game:GetService("Lighting")

local TimeOffset = 10

local function GetClockTime()
	return ((os.date("%H") - TimeOffset)) +
		(os.date("%S") / 3600) +
		(os.date("%M") / 60)
end

print(GetClockTime())

Thank you for this code. However, Iā€™m still running into issues with the cycle repeating.