local runService = game:GetService("RunService")
runService.Heartbeat:Connect(function()
game.Lighting.TimeOfDay = os.date("%X", os.time())
end)
This Script will turn the Lightning Time to my PC Time but im not sure. The os.time comes out as the German Time but i think if somoene from USA or London will join my Game the Time will set to a different Time but i just want to add the German Time, how do i do that?
I would recommend using the DateTime library instead, it has a nicer interface.
I would also recommend using Lighting.ClockTime instead of TimeOfDay so you can provide one number.
So
Get the current time with DateTime.now()
Get the UTC representation with :ToUniversalTime()
Add your desired timezone offset (+2 hours for germany) and use e.g. by using its timestamp to get hours:
local TIMEZONE = 2
local MS_PER_HOUR = 1000 * 60 * 60
local now = DateTime.now().UnixTimestampMillis / MS_PER_HOUR + TIMEZONE
game.Lighting.ClockTime = now % 24
Alternatively to use TimeOfDay you could make another object and format it:
local TIMEZONE = 2
local now = DateTime.now():ToUniversalTime()
local adjusted = DateTime.fromUniversalTime(
now.Year,
now.Month,
now.Day,
now.Hour + TIMEZONE,
now.Minute,
now.Second,
now.Millisecond
)
game.Lighting.TimeOfDay = adjusted:FormatUniversalTime("HH:mm:ss", "en-us")
print(game.Lighting.TimeOfDay)
I made a model that does exactly this in just about 3-4 lines of code. RealTime
The model sets the time of day in lighting to the user’s time on their PC clock.
Must be a problem with your end, remember must be in ReplicatedFirst. This model uses string formatting to directly set Lighting.TimeOfDay instead of doing any sort of minute calculation.