Instead of my lights flashing at random intervals, they go on an off in sequence. How come?
local Time = 5 local descendants = script.Parent.Lights:GetDescendants() if Time == 5 then repeat wait(math.random(1,3)) for index, descendant in pairs(descendants) do if descendant:IsA("PointLight") then descendant.Brightness = .1 wait(.3) descendant.Brightness = 1 end end Time = Time + 1 until Time == 5 end
It's most likely because the randomseed is picking the same number each time. Try this:
local Time = 5 local descendants = script.Parent.Lights:GetDescendants() if Time == 5 then repeat math.randomseed(tick()) -- sets the randomseed to tick(), ensuring a different randomisation every repeat wait(math.random(1,3)) for index, descendant in pairs(descendants) do if descendant:IsA("PointLight") then descendant.Brightness = .1 wait(.3) descendant.Brightness = 1 end end Time = Time + 1 until Time == 5 end
Your script is changing all of the lights' PointLight Brightness at the same time, rather than randomizing which ones are set off, you can add another random sequence down into the table index like so:
local Time = 5 local descendants = script.Parent.Lights:GetDescendants() if Time == 5 then repeat local timer = math.random(1,3) wait(timer) for index, descendant in pairs(descendants) do local randomsequence = math.random(1,2) if descendant:IsA("PointLight") and randomsequence == 1 then descendant.Brightness = .1 wait(.3) descendant.Brightness = 1 end end Time = Time + 1 until Time == 5 end
This way, anytime a light is called in the function, it will either stay on or flicker. However, if you want the lights to flicker together you'd have to directly define them in the function instead of using a table.