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.
Hey, to solve your problem you should use GetPropertyChangedSignal. Here's an example on how you'd use it in your case.
local Lighting = game:GetService("Lighting") Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function() 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)