Custom TOD wont adapt in-game, but will in studio

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I want to achieve a 12-hour TOD system that adapts to player’s timezone.
  2. What is the issue?
    The time is perfectly fine within studio, but the hour gets messed up when going in the actual game.
  3. What solutions have you tried so far?
    I’ve removed some of the script that might have been messing with it and found new ways to check, but it still does not work.
local Lighting = game:GetService("Lighting")
local ProperWait = require(script.ModuleScript)
local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect(function()
	local CurrentTime = DateTime.now():ToLocalTime()
	Lighting.TimeOfDay = ("%.2d:%.2d:%.2d"):format(CurrentTime.Hour, CurrentTime.Minute, CurrentTime.Second)
	ProperWait(1)
	print(Lighting.TimeOfDay)
end)

Needs more information. Don’t know what type of script you’re running or what the exact problem is, such as the prints that are showing that you aren’t getting the intended time. Please supply more information if you can and be sure to explain the problem you’re facing.

On a separate note, I personally wouldn’t use TimeOfDay to code any time systems. I’d always base it off of Get/SetMinutesAfterMidnight or ClockTime because those are a whole lot more scriptable. TimeOfDay is more useful for parsing the current time not for modifying (even though you can modify it).

Also not particularly sure why you’re calling a wait in a Heartbeat connection, not necessary.

I’ve been working more with it and figured out that it isn’t getting the local time at all. I’ve tried switching my system to all kinds of time zones, and it always uses UTC. I’m just using a regular script in ServerScriptService. It should be changing the time to the exact time zone of the user’s device, yet it just uses UTC almost as if it is using :ToUniversalTime() and not :ToLocalTime(). I figured this out by adding CurrentTime.Hour - 5 instead of CurrentTime.Hour.

Right, that’s the issue. The server always works in UTC and doesn’t exactly have a concept of a time zone; if it did then the time zone would be according to the region of the server. If you wanted this system to use the local time then it needs to be running from a LocalScript.

When you use ToLocalTime it attempts to convert the given time into the current machine’s time zone. In a server script the current machine is the server and so it tries to use the server’s perceived local time, not that of a specific client. In a LocalScript the code runs on the user’s machine and as such can fetch the time zone of the client’s machine.

Ahh, got ya. Seemed to over look that. Thanks for the help :stuck_out_tongue: