ClockTime above 24 should apply a modulo of 24

As a Roblox developer, it is currently too hard to tween the Lighting’s ClockTime property to make day-night cycles.


The issue
When you set ClockTime to 24 or above, the property will automatically reset back to 0. This is a problem when you want to tween this property along with others through TweenService; If you tween ClockTime from 22 to 2, you will go back twenty hours in time instead of four hours forward. Normally the fix is to tween ClockTime from 22 to 26, but given that ClockTime resets to 0 for every value of 24 and above, your tween will clamp at midnight halfway through and never reach ClockTime = 2.

The workaround is to tween to ClockTime = 24 with one tween, and then to your next time with another. However, this introduces a lot of issues that are hard to solve. If you tween other properties alongside of ClockTime, how do you figure out what value your other properties should have to preserve the smooth transition between the two tweens? With a linear tween this is fairly simple to solve with a singular multiplication/division, but for the other types such as sine tweens this becomes a difficult problem.


The solution
When ClockTime is set above 24, apply a modulo of 24 instead of resetting it to 0. This means that you will be able to tween past midnight in one tween instead of two. This behavior will also put it in line with the TimeOfDay property where setting it to e.g. “50:00:00” will put it at “02:00:00”.

10 Likes

To clarify, you’re saying that ClockTime should go above the max of 24, and internally the number should just be modulo’d to determine the true time?

I’ve struggled with this problem in the past and never solved it, but wouldn’t this break other games that use ClockTime?

Yes. Basically I would like it to work similar to how TimeOfDay works right now, where setting it above 24:00:00 will automatically adjust it.

Unless those games rely on the behavior that setting ClockTime above 24 resets it to 0, I cannot imagine it breaking any games.

I support but a better workaround is to create a numbervalue object and tween that then use it to apply the clocktime (although its still not ideal)

1 Like

I get around things like this by tweening a numbervalue, and then adding a RenderStepped connection for the duration of the tween to set the desired value (in this case, the modulo of the numbervalue)

1 Like

and here I am still using the old method:

Lighting:SetMinutesAfterMidnight(Lighting:GetMinutesAfterMidnight() + speed))

/shrug