TimeOfDay changing, but Event is not firing..help?

Maybe you could use something like…

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if game.Lighting.ClockTime == 18.5 then -- "18:30:00"
		print("Working!")
                -- Stuff here
	end
end)

Is it printing the numbers as decimals? If it is, Then I think I know the exact issue why

I believe so - yes. This is an example of what it is printing every second. 21:13:22.161 1085.05

I actually tried this prior to using TimeOfDay and it gave me the same outcome. I don’t know why it is so challenging to work with.

I used Avanthyst’s example and it worked perfectly, example code:

local light1 = game:GetService("Workspace"):WaitForChild("1"):WaitForChild("SurfaceLight")
local light2 = game:GetService("Workspace"):WaitForChild("2"):WaitForChild("SurfaceLight")

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if game.Lighting.ClockTime >= 18.5 then
		light1.Enabled = true
		light2.Enabled = false
	else
		light2.Enabled = true
		light1.Enabled = false
	end
end)

Are you using a day/night cycle script? Because it might be setting different numbers to work with the cycle, that’s probably why the value isn’t exactly 18:30:00, as it works fine when testing manually.

That is exactly right - the day/night cycle in my game is being used. I don’t know a workaround without disabling it for this, however. I’m trying to keep the feel of a realistic lighting transition, but it doesn’t appear I can do that without disabling the day/night cycle.

OK Temporary Solution Attempt #2:

local lighting = game:GetService("Lighting")
print("Starting Lighting Cycle...")

game.Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function()
	local TimeConversion = game.Lighting:GetMinutesAfterMidnight()
	print(TimeConversion)
	if TimeConversion < 384 then
		print("Night-Mode Enabled!")
		lighting.Brightness = 0
		lighting.OutdoorAmbient = Color3.fromRGB(116, 116, 116)
		lighting.Ambient = Color3.fromRGB(156, 156, 156)

		--lightA.Enabled = true
		--lightB.Enabled = true
		--lightC.Enabled = true
		--lightD.Enabled = true
		--lightE.Enabled = true
		--lightF.Enabled = true
		--lightG.Enabled = true
		--lightH.Enabled = true
		--lightI.Enabled = true
		--lightJ.Enabled = true
		--lightK.Enabled = true
		--lightL.Enabled = true

	elseif TimeConversion > 384 and TimeConversion < 1080 then
		print("Day-Mode Enabled!")
		lighting.Brightness = 2
		lighting.OutdoorAmbient = Color3.fromRGB(207, 207, 207)
		lighting.Ambient = Color3.fromRGB(163, 163, 163)
	end
end)

You’ll still get a lot of prints, but if everything works correctly then the lighting should change depending what time you’re on

This is very strange - it enabled the DayMode part, but completely skipped the NightMode section.

Would you be able to share your day/night cycle script? Could probably be easier to figure out the issue.


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```

Okay so this is kinda tricky, but it should be working:

local isNight = false

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	local clockTime = tostring(game.Lighting.ClockTime)
	if clockTime:sub(1, 4) == "18.5" and not isNight then -- 18:30:00
		isNight = true
		print("Night cycle!")
		-- Your stuff here
	end
end)

-- Reset 'isNight' to false once it's day time.
1 Like

I edited the script, and I believe I fixed it HOPEFULLY (I legit tested this REEE)

local lighting = game:GetService("Lighting")
print("Starting Lighting Cycle...")

game.Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function()
	local TimeConversion = game.Lighting:GetMinutesAfterMidnight()
	print(TimeConversion)
	if TimeConversion < 384 then
		print("Night-Mode Enabled!")
		lighting.Brightness = 0
		lighting.OutdoorAmbient = Color3.fromRGB(116, 116, 116)
		lighting.Ambient = Color3.fromRGB(156, 156, 156)

		--lightA.Enabled = true
		--lightB.Enabled = true
		--lightC.Enabled = true
		--lightD.Enabled = true
		--lightE.Enabled = true
		--lightF.Enabled = true
		--lightG.Enabled = true
		--lightH.Enabled = true
		--lightI.Enabled = true
		--lightJ.Enabled = true
		--lightK.Enabled = true
		--lightL.Enabled = true

	elseif TimeConversion > 384 and TimeConversion < 1080 then
		print("Day-Mode Enabled!")
		lighting.Brightness = 2
		lighting.OutdoorAmbient = Color3.fromRGB(207, 207, 207)
		lighting.Ambient = Color3.fromRGB(163, 163, 163)
	end
end)
1 Like

This works perfectly. The night-time lighting comes on - the only part I am confused about is how to turn them off once the clock hits the 6.3 mark now. I’m extremely grateful for your assistance.

I think I finally have it figured out - thank you kindly for all of your time spent assisting me. It means the world!

1 Like