Day/Night Cycle Time Interval Limit

The Development Discussion category is for any and all topics related to development on Roblox, as well as topics related to Roblox developers.

  • Topics should contribute something to developers
  • Topics should encourage discussion
  • Topics should be specific
  • Topics should not be for concerns relevant to other categories

For more details on ideal topics to create, please review the category guidelines: https://devforum.roblox.com/t/about-the-development-discussion-category/14

Hello! I believe I have discovered an oddly specific limit to how small of a time interval you can give to the program provided here. This is all run on the server side as I was planning on using lightClock for certain events in my game.

I had noticed this because I was trying to get an even 24 minute day night cycle, which would mean I would need each hour to take one minute. Having a time interval between each event of 1/3600 would mean that 60 frames gives one second, and 60 seconds should give one minute irl, and one hour in game, which it does, I think? I never got to test it because of the limit.

I am wondering what this is, why this limit exists, and potential ways I could reprogram this so I can have a clean 24 minute day night cycle instead of whatever this would result in (despite likely not even being noticeably different to any extent).

Note: If you set the time interval to 1/3598 or smaller this program will stop working at all, it will literally do nothing. Its crazy.

Also if any point in this post is incoherent I apologize, I have been working day and night to try and get my game working nicely, as publishing a game from studio to roblox, a lot of things that work in studio don’t work in roblox, which is really strange, but probably has some solid technical reasons. Its also really easy to fix as it often involves just waiting for certain instances etc either way I am off track. Look at this weird number!

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

--takes one second to do 0.06 clocktime passed
--0 is midnight, 1 is 1 hour after midnight
local function updateTime()

	local currentTime = lighting.ClockTime
	local timeInterval = 1/3597
	local newTime = currentTime + timeInterval

	lighting.ClockTime = newTime

	if currentTime > 6.45 and currentTime < 6.5 then

		currentTime = 6.45

		--fire the event that makes all the rocks come back
		for i=1, table.maxn(brokenRocks), 1 do

			--set health and visibility back
			rockHealth(brokenRocks[i])

			brokenRocks[i].CanCollide = true
			brokenRocks[i].CanTouch = true
			brokenRocks[i].CanQuery = true

			brokenRocks[i].Transparency = 0

			--once loop is done clear rocks
			if i >= table.maxn(brokenRocks) then

				brokenRocks = {}
			end
		end
		print("restored")
	end
end

task.wait(5) -- waits before connecting so game can load

runService.Heartbeat:Connect(updateTime)

First off, this should probably go in help and feedback somewhere. Secondly, you can just make a separate time for it to be based on, here is the script. Essentially, don’t rely on the value provided by the game, as that gets rounded automatically, or you could use the much simpler and nicer method of tweening (recommended).

Note that this would probably make it look a bit choppy, but it should be fine overall.

local runService = game:GetService("RunService")
local lighting = game:GetService("Lighting")
local currentTime = 0
local startTime = os.time()
local startHour = lighting.ClockTime

--takes one second to do 0.06 clocktime passed
--0 is midnight, 1 is 1 hour after midnight
local function updateTime()

	currentTime = os.time()
	local timeForCycle = 1440 --in seconds, time for the time cyle to go through one time
	local newTime = currentTime - startTime

	lighting.ClockTime = newTime + startHour

	if currentTime > 6.45 and currentTime < 6.5 then

		currentTime = 6.45

		--fire the event that makes all the rocks come back
		for i=1, table.maxn(brokenRocks), 1 do

			--set health and visibility back
			rockHealth(brokenRocks[i])

			brokenRocks[i].CanCollide = true
			brokenRocks[i].CanTouch = true
			brokenRocks[i].CanQuery = true

			brokenRocks[i].Transparency = 0

			--once loop is done clear rocks
			if i >= table.maxn(brokenRocks) then

				brokenRocks = {}
			end
		end
		print("restored")
	end
end

task.wait(5) -- waits before connecting so game can load

runService.Heartbeat:Connect(updateTime)

Alternatively, you could just use TweenService.

local Lighting = game:GetService("Lighting")
local TweenS = game:GetService("TweenService")
local TweenI = TweenInfo.new(1440,Enum.EasingStyle.Linear, Enum.EasingDirection.In) --first value is how long you want it to take

Lighting.ClockTime = 0
local toMidnight = TweenS:Create(Lighting,TweenI,{ClockTime = 24})

while true do
	toMidnight:Play()
	toMidnight.Completed:Wait()
end
1 Like

alright sweet first thing im going to do is see if I can switch the topic. Thanks again man seriously.

Also, allow me to explain further in depth why your problem occurs. game.Lighting.ClockTime rounds when it is converted into Hour:Minute:Second time. Hour minute second, roblox will convert it, and truncate whatever second value is left over, for example 7.3 seconds becomes 7 seconds. Now, it is likely just an error with inexactness in the computer that it stops at 1/3598, rather than 1/3600, because mine works all the way up to 1/3610.

In short, it results from truncating when converted into Hour:Minute:Second time, and impreciseness of the numbers.

1 Like

That makes a lot of sense because it seemed like such a random value and it was rounding to zero otherwise it would be displaying some kind of movement.

Thanks so much for the help again, usually my post would be a lot more clear (or at least in the right topic) but my brain is completely fried and I am genuinely really grateful for your patience and the clear explanation!

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