Day Night Cycle Help

I have a simple day night cycle script and was wondering if someone can help me make the daytime 10ish minutes and the night time also 10ish minutes. Idk how to do it.

local RunService = game:GetService("RunService")
local Lighting = game:GetService("Lighting")

local function updateTime()
 local currentTime = Lighting.ClockTime
 local timeInterval = 0.0002
 local newTime = currentTime + timeInterval
 Lighting.ClockTime = newTime
end

RunService.Heartbeat:Connect(updateTime)

Probably not the best script but it works

local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")
local Duration = 600 -- day and night duration (in seconds)

local totalTime = 0
local function Update(deltaTime)
	totalTime = totalTime % Duration + deltaTime
	Lighting.ClockTime = 24 * (totalTime / Duration)
end

RunService.Heartbeat:Connect(Update)
3 Likes

This works a lot better but when I start the game it starts during the night.

Because variable totalTime is 0, just change it to other number

it didnt change the time, i set it to 12

to change it, you need to do:

local totalTime = 24 * 12

-- 12 is the hour you want it to start at
-- this will set it to 12 pm

Is there a way to change it after it starts?

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