Answers for "day/night cycle script roblox"

1

Day/Night script in roblox studio

-- dayLength defines how long, in minutes, a day in your game is. Feel free to alter it.
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
Posted by: Guest on October-16-2020
0

day night cycle roblox

local length = 12
--length is in minutes

local cycle = length*60
local minutes = 24*60

local lighting = game:GetService("Lighting")

local start = tick() - (lighting:getMinutesAfterMidnight() / minutes)*cycle
local TimeEnd = start + cycle

local Ratio = minutes / cycle

if length == 0 then
	length = 1
end

repeat
	local current = tick()
	
	if current > TimeEnd then
		start = TimeEnd
		TimeEnd = start + cycle
	end
	
	lighting:setMinutesAfterMidnight((current - start)*Ratio)
	wait(1/15)
until false
Posted by: Guest on July-31-2021

Browse Popular Code Answers by Language