So I have a loop which makes lights flicker.
The lights are inside of a folder and a for loop is used to get the lights, however the problem is that the lights all flicker at the same time, so how could I make the lights flicker at different times?
CODE:
local function FlickerLight()
workspace.FlickerLoop:Play()
while CanFlicker do
local RandomInterval = math.random(.1, 1)
for i, v in pairs(LightsFolder) do
if v:IsA("SurfaceLight") or v:IsA("SpotLight") then
local Light = v
--print(v)
local LightEffect = Light.Parent
--print(Light)
--print(LightEffect:GetChildren())
local FlickerLoopSound = LightEffect:FindFirstChild("LightFlickerLoop")
local FlickerSound = LightEffect:FindFirstChild("LightFlicker")
local FlickerSound2 = LightEffect:FindFirstChild("LightFlicker1")
--print(FlickerLoopSound)
coroutine.wrap(function()
--FlickerLoopSound.Playing = true
local r = math.random(1,2)
if r == 1 then
--FlickerSound:Play()
else
--FlickerSound2:Play()
end
Light.Enabled = false
LightEffect.Material = Enum.Material.Plastic
-- print('disabled')
task.wait(.5)
-- print('enabled')
Light.Enabled = true
LightEffect.Material = Enum.Material.Neon
end)()
end
end
task.wait(.1)
end
end
FlickerLight()