How could I smoothly tween time?

How would I be able to smoothly tween TimeOfDay or ClockTime?
Of course you would just tween it normally, but the issue is:
If I want to tween the time from 22 to 2, instead of the clock going 4 hours forward, it goes 20 hours backwards.
This obviously looks very stupid and unnatural.

So here is how my time script works:
Every second the Minute value gets increased by 1
If the Minutes value is 60 the set Minutes to 0 and increase Hours by 1.
If Hours reaches one of the values listed below, it sets the ClockTime to that value.
On hours 4, 6, 9, 12, 17, 21, 24 (0) properties of Lighting get changed.
I already figured out how to tween the fog, ambient, etc. Im just stuck at the time.

The only thing I figured out so far is that if Hours reaches 0, tween ClockTime to 23.999 and check every frame if the ClockTime is 23.999 and if so set it to 0.001.
This works correctly, but only if the time goes forward.
If I change the time from 2 to 22, the clock adds 20 hours instead of going 4 hours back.

2 Likes

I just had to do this yesterday. This is what I used to go forward, backward may not work:

local function changeTimeForward(last)
  repeat
     game:GetService("Lighting").ClockTime += 0.01
     wait(0.01)
  until game:GetService("Lighting").ClockTime == last
end

local function changeTimeBackward(first, last)
  if last > first then
     repeat
        game:GetService("Lighting").ClockTime = game:GetService("Lighting").ClockTime - 0.01
        wait(0.01)
     until game:GetService("Lighting").ClockTime == 0.01
     wait(0.02)
     game:GetService("Lighting").ClockTime = 23.99
     repeat
        game:GetService("Lighting").ClockTime = game:GetService("Lighting").ClockTime - 0.01
        wait(0.01)
     until game:GetService("Lighting").ClockTime == last
  else
    repeat
       game:GetService("Lighting").ClockTime = game:GetService("Lighting").ClockTime - 0.01
       wait(0.01)
    until game:GetService("Lighting").ClockTime == last
end

Tell me if this is what you wanted and if it works

1 Like