How do you make an advanced Day/Night Cycle Script?

Hello, I am just making stuff for my future game(s) and as of now I am working on an advanced Day Night cycle script for example every 200 cycles of day and night the lighting is different does anyone know how to do that? Here is my script as of now.

local dayLength = 12

local cycleTime = dayLength*60
local minutesInADay = 24*60

local lighting = game:GetService("Lighting")

local startTime = tick() - (lighting:getMinutesAfterMidnight() / minutesInADay)*cycleTime
local endTime = startTime + cycleTime

local timeRatio = minutesInADay / cycleTime

if dayLength == 0 then
	dayLength = 1
end

repeat
	local currentTime = tick()
	
	if currentTime > endTime then
		startTime = endTime
		endTime = startTime + cycleTime
	end
	
	lighting:setMinutesAfterMidnight((currentTime - startTime)*timeRatio)
	wait(1/15)
until false
4 Likes
local dayDuration = 3_600 --last for an hour (3,600 s)

    --in a yielding loop
    ctime = (1440 *  time() / dayDuration) % 1440 --1440 is 24 * 60
    nightTime = ctime >= 1080 and ctime < 360 --18 * 60 (6:00 pm) and 6 * 60 (6:00 am)
    --use the above boolean for something like street lights
    lighting:SetMinutesAfterMidnight(ctime)
5 Likes

Ah thank you so much for your time and help!

Wait I just realized where is the part of the script that I can customize the color of the example 200 cycles?

You can remove the % 1440 from the ctime calculation and then just base the colors off of something like this

floor(ctime / 1440) % 200 --0 through 199 based on the day
1 Like

ah thank you, I was just confused. :slight_smile:

Roblox dont find “lightining” instance help!

2 Likes