Help with for pairs loop

Whatt do you want to achieve?

So, I’m coding a system where as long as the script is enabled, all the PointLights in a folder will flicker at the same time continously.

What is the issue?

They are not flickering at the same time, they seem to be following an order, one by one.

What solutions have you tried so far?

I’ve searched on the forum and on Youtube, but I can’t manage to make it work.

This is the code:

local descendants = game.Workspace.LightSystem:GetDescendants()

while true do

for i, descendant in pairs(descendants) do
if descendant:IsA(“PointLight”) then
descendant.Brightness = 0
wait(.125)
descendant.Brightness = 0.25
wait(.125)
end
end
end

1 Like

Alright i see the problem.
Make the wait after your loop.
That happened because you made wait(0.125) in loop and it happen every time you change your descendant’s Brightness and it stops whole script.

local descendants = game.Workspace.LightSystem:GetDescendants()

while true do

   for i, descendant in pairs(descendants) do
   	if descendant:IsA("PointLight") then
   		descendant.Brightness = 0
   	end
   end
   wait(.125)
   for i, descendant in pairs(descendants) do
   	if descendant:IsA("PointLight") then
   		descendant.Brightness = 0.25
   	end
   end
   wait(.125)
end
1 Like

It really worked!. Thank you so much! It worked perfectlty.