[FIXED] Problem with a street light system

  1. What do I want to achieve?
    I want to enable street lights when it’s night and disable them when it’s day.

  2. What is the issue?
    It’s just not enabling the SurfaceLights and changing the material to Neon. (Tell me if you need screenshots)

  3. What solutions have you tried so far?
    I tried changing the while true do to while wait(.1) do, I also tried changing the order of the script.

The error may be very stupid but I didn’t really notice any.

local lampsFolder = workspace.StreetLamps
local lightingService = game.Lighting
local cT = lightingService.ClockTime

while wait(.1) do
	if cT >= 18 and cT < 7 then
		for _, lamp in pairs(lampsFolder:GetDescendants()) do
			if lamp.Name == "LPart" then
				lamp.Material = Enum.Material.Neon
			elseif lamp:IsA("SurfaceLight") then
				lamp.Enabled = true
			end
		end
	elseif cT >= 7 and cT < 18 then
		for _, lamp in pairs(lampsFolder:GetDescendants()) do
			if lamp.Name == "LPart" then
				lamp.Material = Enum.Material.SmoothPlastic
			elseif lamp:IsA("SurfaceLight") then
				lamp.Enabled = false
			end
		end
	end
end

I hope it’s clear enough. Thanks to anyone who will help me in advance!

1 Like

HAHAHAHHA LOL
anyways sorry, I actually have tried this before, but in your case you want ONE script to deactivate ALL lights that are on. You CAN do that, but ill just explain.
Example:

while true do
wait()
if game.lighting.clocktime == 7 then — 7 as in 7AM (Day)
(turning off all light code here)
end
if game.lighting.clocktime == 24 then — 24 as in 12AM (Night)
(turning on all light code here)
end
end

This is just an example, NOT an actual script, so use this as reference and an example. Hope it helps.

1 Like

well, i said it was probably a dumb error lol but sadly your example didn’t work. Thanks for the help anyway.

Make the ‘cT’ variable inside the loop not outside. When you make a variable It doesn’t change unless you ‘update’ it for lack of a better word
Basically say your ClockTime is 11.7 and when you run the script the cT variable will never change away from 11.7 it’ll just stay the same
All you need to do is is move

local cT = lightingService.ClockTime

Right after

while wait(.1) do
1 Like

sorry but this didn’t work, i’ll actually try to change it via the day night cycle.

Is there a script that changes the clock time?
Like a daylight cycle script.

1 Like

yeah the code is simple it’s just

while wait(1) do
	game.Lighting.ClockTime = game.Lighting.ClockTime + 1
end
1 Like

Figured it out
Its because when you check if the time is in the correct range you are using ‘and’
If ClockTime is 20 it will be greater than 18 but not less than 7
Change ‘and’ to ‘or’ and it should work fine
Also maybe try using

lightingService:GetPropertyChangedSignal("ClockTime"):Connect(function()
    -- do stuff
end)

Instead of a infinite loop

1 Like

Thank you very very very much, it worked! I think it’s because I started to script my system with minutes then switched to ClockTime hours.

1 Like