Adjusting 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 time to adjust for this, but I am not sure how to do this arithmetic. The code is provided below.

local Duration = 180 (DAY TIME) (DECREASE)
local Inside = 30 (AFTERNOON) (STILL)
local Diff = 60 (NIGHT) (INCREASE)

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)
--game.Lighting.ClockTime = 6

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)
--game.Lighting.ClockTime = 24
	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
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

Bro just copied and pasted the code. Are you a bot of some sort?

It’s not copy & paste I editted some of your code lol

Sorry, what did you change? I would like an explanation also.

You had updateCountdownLabel("Stay in the cabin and survive: " .. tostring(i)) so I fixed it by putting it in a for loop. You had no loop for Diff var so I added a loop. During inside phase clocktime increments werent correct

How would this make it so the day and night time are the same regardless of the Duration time? For example I would want night time to be the same whether it lasts 60 seconds or 120 seconds.

It just makes sure that night time increases whether the day is 60,120,etc. you can rescale increments if you wanna change how clocktime changes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.