FallingPrisms' Day-Night Cycle - Advanced Lightweight Day-Night Cycle

INTRODUCTION
Ever needed a way to change the in-game time easily? Look no further with FallingPrisms’ Day-Night Cycle. This Day-Night Cycle is extremely easy to set up and use. With multiple configurations to perfectly choose how you want it to look like. These configurations include WaitTimeInSeconds, AddedHour, WaitTime, and AddedTime. More information about those specific variables is inside the script itself.

VIDEO

CODE

-- // Efficient Day-Night Cycle; By: FallingPrisms

-- // Services
local LightingService = game:GetService("Lighting")

-- // Variables;
local AddedHour = 1
local WaitTimeInSeconds = 60

-- Don't change thses unless you know what you are doing
local WaitTime = 0.03 -- Shrinking these numbers will make the transition smoother
local AddedTime = 0.1

--[[
Recommended Times:

{AddedTime = 1, WaitTimeInSeconds = 60} = 24 minutes for one day.
{AddedTime = 1, WaitTimeInSeconds = 30} = 12 minutes for one day.
{AddedTime = 2, WaitTimeInSeconds = 120} = 24 minutes for one day, larger time change.
{AddedTime = 2, WaitTimeInSeconds = 60} = 12 minutes for one day, larger time change.
--]]

-- // Functioms
local function UpdateTime(NewTime)
	if NewTime == 24 then
		NewTime = 0
	end
	
	repeat
		LightingService.ClockTime = LightingService.ClockTime + AddedTime
		
		if LightingService.ClockTime > NewTime then -- This isn't super necessary, but good to have incase problems occur
			LightingService.ClockTime = NewTime
		end
		
		task.wait(WaitTime)
	until LightingService.ClockTime == NewTime
end

local function HandleTime()
	while true do
		UpdateTime(LightingService.ClockTime + AddedHour)
		
		task.wait(WaitTimeInSeconds - 0.3) -- Subtracts from UpdateTime delay
	end
end

HandleTime()

CONCLUSION
Thank you for reading this post, it means a lot to me. Please let me know if you have any questions!

Link to Place: https://www.roblox.com/games/8448319077/Day-Night-Cycle
Link to Model: Day Night Cycle - Model

3 Likes

You can make it smoother using tweenservice, it will get complicated but at result, it would be much smoother

1 Like

This would be smoother, but tweening on the server is not a very good idea because it has to replicate to all the clients.