Street lamp that automatically turn on when night time

I have spent a lot of time to make this and it not working( output don’t count its as an error so I guess I dunno)\

script:

local lightingpart = script.Parent.Light
local light = lightingpart.SpotLight.Enabled
local times = game.Lighting.ClockTime

while true do
	if times >= 17.8 or times <= 6.7 then
		light = true
		lightingpart.Material = "Neon"
	elseif times <= 17.8 or times >= 6.7 then
		light = false
		lightingpart.Material = "SmoothPlastic"
	end
	wait(1)
end

I can’t find any error in my own script
I’m not a programmer and I am not good at it.
any reply is appreciated :happy4:
I’m a noob

Maybe try “game.Lighting:GetMinutesAfterMidnight()”, instead of just checking the ClockTime?

It mite have something to do with normalizing the time.

try this

local lightingpart = script.Parent.Light
local light = lightingpart.SpotLight

while true do
	times = game.Lighting.ClockTime
	if times >= 17.8 or times <= 6.7 then
		light.Enabled = true
		lightingpart.Material = "Neon"
	else
		light.Enabled = false
		lightingpart.Material = "SmoothPlastic"
	end
	wait(1)
end
1 Like
local parent = script.Parent
local lightingpart = parent:WaitForChild("Light")
local light = lightingpart:WaitForChild("SpotLight")
local lighting = game:GetService("Lighting")

while task.wait(1) do
	if lighting.ClockTime >= 17.8 or lighting.ClockTime <= 6.7 then
		light.Enabled = true
		lightingpart.Material = "Neon"
	elseif lighting.ClockTime <= 17.8 or lighting.ClockTime >= 6.7 then
		light.Enabled = false
		lightingpart.Material = "SmoothPlastic"
	end
end

Try this as it is more efficient since it fires if the property changes and not every sec.

local lightingpart = script.Parent.Light
local light = lightingpart.SpotLight.Enabled

lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
    local times = game.Lighting.ClockTime
	if times >= 18 or times <= 6 then
		light = true
		lightingpart.Material = "Neon"
	elseif times <= 18 or times >= 6 then
		light = false
		lightingpart.Material = "SmoothPlastic"
	end
end)

@Forummer tnx for ur input.

This would likely cause studio to crash because there’s no yield.

thank you, altho i have to edit the script a bit