Why is my script not able to detect when ClockTime reaches 15?

  1. What do you want to achieve?
  • Have this day/night cycle script be able to stop when ClockTime reaches exactly 15.
  1. What solutions have you tried so far?
  • Tried to string clocktime into main double digits only.

Title say it all, having an unusual brainfart struggle to figuring it out why clocktime is being ignored when it reaches 15.

local LightingService = game:GetService("Lighting")
local Settings = game:GetService("ReplicatedStorage")._DATA_WR.Settings  --Folder containing values
local WeatherFolder = game:GetService("ReplicatedStorage")._DATA_WR.Weather --Folder containing values
local Current = WeatherFolder.Current --Folder containing values
local Monthly = WeatherFolder.Monthly --Folder containing values
local ForecastDay = WeatherFolder.ForecastDay --Folder containing values
local ForecastNight = WeatherFolder.ForecastDay --Folder containing values
local Modules = Settings.Parent.Modules --Folder containing Several modules

local EnableSkyEnvironment = Settings:FindFirstChild("EnableSkyEnvironment") --BoolValue

local SunDynamicPath = require(Modules.SunPath) --ModuleScript
local MoonPhraseImageIDModule = require(Modules.MoonPhaseImage) --ModuleScript
local MoonPhase = Settings.MoonPhase --NumberValue
local Skybox = LightingService:FindFirstChildWhichIsA("Sky") --Classname:IsA("Sky")

local EnabledOfSettings = Settings.EnableSkyEnvironment.Value --BoolValue
local AdvanceDayOfYear = require(Modules.YearCalculatorEqt) --ModuleScript

repeat
	local DynamicSpeed = 1000
	local BasicSpeed = 1
	local waitTime = task.wait()

	if EnabledOfSettings and AdvanceDayOfYear then

		SunDynamicPath.ClockTime += (DynamicSpeed / 3600) * waitTime
		SunDynamicPath.DayOfYear += (DynamicSpeed / 86400) * waitTime

		print(tostring(math.floor((LightingService.ClockTime)))) 

		if LightingService.ClockTime == 6 then --# This specific line is giving me most of the troubles.
			MoonPhase.Value += 1
			for value, Phase in pairs(MoonPhraseImageIDModule.MoonPhaseData)do
				if MoonPhase.Value >= 24 then
					Skybox.MoonTextureId = MoonPhraseImageIDModule.MoonPhaseData[0]
					MoonPhase.Value = 0
				elseif MoonPhase.Value == value then
					Skybox.MoonTextureId = Phase
				end
			end
		end
			--[[if Settings.LockTime ~= "" then
				--ChangeLighting()
			end]]--
	end
until 1 == 0
	--[[spawn(function()
		repeat
			#TestFunction
		until 1 == 0
	end)]]--

Use this

if math.floor(LightingService.ClockTime) == 6 then

and tell me the result

Unfortunately, still having the existing issue of it ignoring the timeclock, and MoonPhase value was not added to update the moon.

Does it just ignore or does the clock won’t hit 6?

Retried it again, and there is progress of good success. Just mildy rapid change in progression of value.

do you mean the rapid change of the moonphase? it’s simple, add a debounce.

Maybe try something like this ?

game:GetService'Lighting':GetPropertyChangedSignal"ClockTime":Connect(function() 
print(game:GetService'Lighting'.ClockTime)
end)

A floating point number, not an exact integer. It will almost never be exactly 6 or 15.

if LightingService.ClockTime > 6 and LightingService.ClockTime < 7 then
    -- 
end
if LightingService.ClockTime > 15 and LightingService.ClockTime < 16 then
    -- 
end

Or maybe.. This would narrow the fire window with a debounce

local db = true
while task.wait(1) do --whatever loop you have going
    local t = LightingService.ClockTime
    if db and t > 15 and t < 15.02 then db = false
      --
    elseif db and t > 15.02 then db = true
    end

end

Tried the debounce method, but only end up getting the breaks into the loops.

if math.floor(LightingService.ClockTime) == 6 then --# This specific line is giving me most of the troubles.	
			if not debounce then
			debounce = true
			MoonPhase.Value += 1
			for value, Phase in pairs(MoonPhraseImageIDModule.MoonPhaseData)do
				if MoonPhase.Value >= 24 then
					Skybox.MoonTextureId = MoonPhraseImageIDModule.MoonPhaseData[0]
					MoonPhase.Value = 0
				elseif MoonPhase.Value == value then
					Skybox.MoonTextureId = Phase
				end
			end
				debounce = false --Breaking point
			end
		end

I tried this before with getproperty and had weird issues with it were it would just completely ignore the propertychangesignal.

I have my loop currently running as repeat

repeat
--Code Here
until 1 == 0

I take this may not be the most viable approach?

if LightingService.ClockTime > 5.99 and LightingService.ClockTime < 6.01 then
	if not debounce then debounce = true
		MoonPhase.Value += 1
		if MoonPhase.Value >= 24 then
			MoonPhase.Value = 0
		end
		Skybox.MoonTextureId = MoonPhraseImageIDModule.MoonPhaseData[MoonPhase.Value]
		debounce = false
	end
end
-- 5.999 and LightingService.ClockTime < 6.001

UPDATE:
I eventually did manage to get it to work, its not the most nice thing but it gets the job done and does it surprisingly fairly well.

local MoonPhraseFunction = coroutine.create(function()
		if(MoonPhasePaused) then
			coroutine.yield()
		end
		
		MoonPhase.Value += 1
		
		for value, Phase in pairs(MoonPhraseImageIDModule.MoonPhaseData)do
			if MoonPhase.Value >= 24 then
				Skybox.MoonTextureId = MoonPhraseImageIDModule.MoonPhaseData[0]
				MoonPhase.Value = 0
			elseif MoonPhase.Value == value then
				Skybox.MoonTextureId = Phase
			end
		end
		
	end)
	RunService.Heartbeat:Connect(function()
		
		if EnabledOfSettings and AdvanceDayOfYear then
			
			SunDynamicPath.ClockTime += (DynamicSpeed / 3600) * waitTime
			SunDynamicPath.DayOfYear += (DynamicSpeed / 86400) * waitTime

			print(tostring(math.floor((LightingService.ClockTime)))) 

			if ("%d"):format(LightingService.ClockTime) == "6" then
				if Debounce then
					Debounce = false
					MoonPhasePaused = true
					coroutine.resume(MoonPhraseFunction)
				end
			else
				Debounce = true
				MoonPhasePaused = false
			end
			
			--[[if Settings.LockTime ~= "" then
				--ChangeLighting()
			end]]--
		else
			game.Lighting:SetMinutesAfterMidnight(game.Lighting:GetMinutesAfterMidnight() + BasicSpeed)
		end
	
	--[[spawn(function()
		repeat
			#TestFunction
		until 1 == 0
	end)]]--

	end)
end

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