Day Night Arithmetic

Hello, I am trying to attempt a day and night cycle. However, I need the times to adjust to an increase in interval. How the system works is that initially daytime will be 180 seconds but every day it will decrease by 30. Also, nighttime is initially 60 seconds but increases by 20 seconds every day. I need the day and night time to always be the same, but allow the duration of the day and night to be different.

local Duration = 180 
local Inside = 30 
local Diff = 60 

while true do
    game.Lighting.FogEnd = 750
    game.Lighting.FogColor = Color3.new(0.4, 0.631373, 0.737255)
    game.Lighting.ClockTime = 12
    
    for i = Duration, 1, -1 do
        updateCountdownLabel("Gather resources: " .. tostring(i))
        task.wait(1)
        game.Lighting.ClockTime += 0.02
    end

    game.Lighting.FogEnd = 500
    game.Lighting.FogColor = Color3.new(0.247059, 0.396078, 0.458824)
    
    for i = Inside, 1, -1 do
        updateCountdownLabel("Get in the cabin and close the door: " .. tostring(i))
        task.wait(1)
        game.Lighting.ClockTime += 0.05
    end
    
    game.Lighting.FogEnd = 50
    game.Lighting.FogColor = Color3.new(0, 0, 0)
    
    for i = Diff, 1, -1 do
        updateCountdownLabel("Stay in the cabin and survive: " .. tostring(i))
        spawnZombie()
        task.wait(1)
        game.Lighting.ClockTime += 0.05
    end
    
    if Duration > 30 then
        Duration -= 30
    end
    Diff += 20
end```
1 Like

Heres the modified version for your request if this helped mark it as solution

local DayDuration = 180
local NightDuration = 60
local DecreaseRate = 30
local IncreaseRate = 20

while true do
game.Lighting.FogEnd = 750
game.Lighting.FogColor = Color3.new(0.4, 0.631373, 0.737255)
game.Lighting.ClockTime = 12

for i = DayDuration, 1, -1 do
    updateCountdownLabel("Gather resources: " .. i)
    task.wait(1)
    game.Lighting.ClockTime += 0.02
end

game.Lighting.FogEnd = 500
game.Lighting.FogColor = Color3.new(0.247059, 0.396078, 0.458824)

for i = 30, 1, -1 do
    updateCountdownLabel("Get in the cabin and close the door: " .. i)
    task.wait(1)
    game.Lighting.ClockTime += 0.05
end

game.Lighting.FogEnd = 50
game.Lighting.FogColor = Color3.new(0, 0, 0)

for i = NightDuration, 1, -1 do
    updateCountdownLabel("Stay in the cabin and survive: " .. i)
    spawnZombie()
    task.wait(1)
    game.Lighting.ClockTime += 0.05
end

if DayDuration > DecreaseRate then
    DayDuration -= DecreaseRate
end
NightDuration += IncreaseRate

end

This is not what I meant, I need a system where regardless of the duration of night and day, the time the sun sets and rises is always the same

you said that u needed them to increase and decrease and adjust smth

i meant where regardless of how long day time lasts, the sun will still set at time = 0. this means that 180 seconds and 30 second day times will still have the same sun set time