Still have questions? Join our Discord server and get real time help.
Log in to vote
0

# Day/Night Cycle System can't go any slower?

Asked by 4 days ago

Right now I would like the day cycle to be slower, but it seems that I can't make it much slower.

while RS.Stepped:Wait() do
local Clock = Lighting.ClockTime
local Speed
if (Clock > 5 and Clock < 8) or (Clock > 16 and Clock < 20) then
Speed = 20 -- Transitions go the fastest
end
if Clock >= 20 and Clock <= 6 then
Speed = 1 -- Nights are shorter than days
else
Speed = 0.0003
end
Lighting.ClockTime = Clock + Speed
end


0.0003 is the current speed set for Day, which means the clock time increases by roughly 1 every minute. Reducing this 0.0003 value will break the system since I assume the values are too low.

But how would I make the day time slower if reducing this 0.0003 value won't work?

### 1 answer

Log in to vote
0
Answered by
Vathriel 477
4 days ago
Edited 4 days ago

You don't need to add to the speed on every step. You can use a modulus to reduce the speed even further.

local StepCount = 0

while RS.Stepped:Wait() do
StepCount = StepCount + 1
local Clock = Lighting.ClockTime
local Speed
if (Clock > 5 and Clock < 8) or (Clock > 16 and Clock < 20) then
Speed = 20 -- Transitions go the fastest
end
if Clock >= 20 and Clock <= 6 then
Speed = 1 -- Nights are shorter than days
else
if StepCount % 10 == 0 then
Speed = 0.0003
else
Speed = 0
end
end
Lighting.ClockTime = Clock + Speed
if StepCount % 10 == 0 then
StepCount = 0 --To prevent floating errors with extremely large step counts
end
end


In this case only every 10th step will the clock change. We need to remember what can happen with arithmetic in computers, so to adjust for potential integer overflows we have reset the step count as well every 10th step. This needs to be done with a separate if statement because we can't guarantee that the StepCount wouldn't overflow in the other sections of code without doing further math, so it does add an extra if statement.