Hello,
I have a little problem and is easy to be fixed I guess but I don't know how.
I have streetlights in my game and they must pretend to be broken.
My intention was that they will start flickering at 6PM (18:00:00) till 6AM (06:00:00).
The problem is they stop flickering when it is midnight/00:00:00.
Line 25 to 29 is the flickering part.
Here the script.
local Lights = workspace:WaitForChild('Lights')
local BrokenStreetLights = Lights:WaitForChild('BrokenStreetLights')
local Lighting = game:GetService('Lighting')
function SetLights(bool)
if bool == "on" then
for i,v in pairs(BrokenStreetLights:GetDescendants()) do
if v:IsA('SpotLight') and v.Parent:IsA('BasePart') then
v.Enabled = true
v.Parent.Material = Enum.Material.Neon
v.Parent.Transparency = 0
end
end
elseif bool == "off" then
for i,v in pairs(BrokenStreetLights:GetDescendants()) do
if v:IsA('SpotLight') and v.Parent:IsA('BasePart') then
v.Enabled = false
v.Parent.Material = Enum.Material.Glass
v.Parent.Transparency = .25
end
end
end
end
while wait() do
if Lighting.TimeOfDay >= "18:00:00" then
SetLights("off")
wait(0.05)
SetLights("on")
elseif Lighting.TimeOfDay >= "06:00:00" then
SetLights("off")
end
end
I hope someone can help me. Keep in mind im a beginning scripter.

6 comments
I tried the code and it doesn't work or I'm doing something wrong. I tried inserting the code at line 25 and 26 so I did it with and without the while loop.
Replace line 25 in your script with line 3 in this script, and add a closing paranthesis at line 33 in your script.
I did what you said and now I have the same result as before the light is flickering.. BUT it stops when midnight/00:00:00 hits in roblox.
You obviously need to remove the >= in line 26 and 30, make them both ==
It doesn't work, its not flickering anymore.
I assume you have a "Day/Night" cycle then, causing the TimeOfDay to not reach exactly 18:00:00/06:00:00