Streetlight script not working at all

I was trying to make a street light script for my game, but for some reason its just not working at all:

local Lighting = game:GetService("Lighting")
local LightGroup = script.Parent:FindFirstChild("Light")
local Light = LightGroup:FindFirstChild("Light")
local PrimaryLightColor

local IsLightOn = script:FindFirstChild("IsLightOn")
local IsLightOrange = script:FindFirstChild("IsLightOrange")

local SpotLight = Light:WaitForChild("SpotLight")

if IsLightOrange.Value == true then
	PrimaryLightColor = Color3.fromRGB(181, 122, 47)
else
	PrimaryLightColor = Color3.fromRGB(255, 255, 255)
end

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if (Lighting.ClockTime > 6.25) and (Lighting.ClockTime < 17.5) then
		print("es")
		IsLightOn.Value = false
		SpotLight.Enabled = false
		Light.Material = Enum.Material.Glass
		Light.Color = Color3.fromRGB(68, 65, 67)
		Light.Transparency = 0.35
	elseif (Lighting.ClockTime < 6.25) and (Lighting.ClockTime > 17.5) then
		print("e")
		IsLightOn.Value = true
		SpotLight.Enabled = true
		Light.Material = Enum.Material.Neon
		Light.Color = PrimaryLightColor
		SpotLight.Color = PrimaryLightColor
		Light.Transparency = 0
	end
end)

I already tried print debugging, it didn’t print anything in either of them.
Thanks in advance! (I believe the problem is in the property change signal)

2 Likes

You don’t need to use parenthesis in your if statements.
From what I’ve researched, it looks like you called it properly.

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if Lighting.ClockTime > 6.25 and Lighting.ClockTime < 17.5 then
		print("es")
		IsLightOn.Value = false
		SpotLight.Enabled = false
		Light.Material = Enum.Material.Glass
		Light.Color = Color3.fromRGB(68, 65, 67)
		Light.Transparency = 0.35
	elseif Lighting.ClockTime < 6.25 and Lighting.ClockTime > 17.5 then
		print("e")
		IsLightOn.Value = true
		SpotLight.Enabled = true
		Light.Material = Enum.Material.Neon
		Light.Color = PrimaryLightColor
		SpotLight.Color = PrimaryLightColor
		Light.Transparency = 0
	end
end)
3 Likes

Also, have you checked to see if the function gets called?

3 Likes

Yeah for some reason the function is just not being called.

2 Likes

Try using this.

while wait() do
	if Lighting.ClockTime > 6.25 and Lighting.ClockTime < 17.5 then
		print("es")
		IsLightOn.Value = false
		SpotLight.Enabled = false
		Light.Material = Enum.Material.Glass
		Light.Color = Color3.fromRGB(68, 65, 67)
		Light.Transparency = 0.35
	elseif Lighting.ClockTime < 6.25 and Lighting.ClockTime > 17.5 then
		print("e")
		IsLightOn.Value = true
		SpotLight.Enabled = true
		Light.Material = Enum.Material.Neon
		Light.Color = PrimaryLightColor
		SpotLight.Color = PrimaryLightColor
		Light.Transparency = 0
	end
end
3 Likes

It still doesn’t work for some reason. Im not really sure why though, for some reason when the time changes to night it still prints ‘es’

2 Likes

It might be an issue with variables then. Have you made sure that everything is in the right place?

3 Likes

All of the variables are in the correct place!

Have you tried checking to see if the change actually happened in the instances?
e.g. IsLightOn shows true or false

If you are still having issues with this I made a detailed explanation on a night-light system similar to this.

1 Like

Alright, I found the issue. I wasn’t using a daylight cycle which set GetMinutesAfterMidnight(). Instead I was changing the time manually which obviously did not work.