Changing multiple objects, waiting 30 seconds, and changing all those objects back again simultaneously

I’m working on a lighting system which uses one brick to detect when the lights should turn on, then after 30 seconds, turn all the lights off again.
The main issue I’m having here is that, when the script is triggered, it turns one light on, waits 30 seconds, then turns the next light on, etc.
My code so far:

for _,light in pairs(area:GetChildren()) do if(light:IsA("Model")) then
    local part = light.LightPart
    part.SurfaceLight.Enabled,part.Material,part.BrickColor = true,"Neon",BrickColor.new("Cadet blue")
    wait(30)
    part.SurfaceLight.Enabled,part.Material,part.BrickColor = false,"Metal",BrickColor.new("Medium stone grey")
end end
1 Like

You can wrap it in a coroutine or you can just make a second loop where the wait command is in between the two loops:

coroutine.create(function()
    local part = light.LightPart
    part.SurfaceLight.Enabled,part.Material,part.BrickColor = true,"Neon",BrickColor.new("Cadet blue")
    wait(30)
    part.SurfaceLight.Enabled,part.Material,part.BrickColor = false,"Metal",BrickColor.new("Medium stone grey")
end)

or

for _,light in pairs(area:GetChildren()) do 
    if(light:IsA("Model")) then
        local part = light.LightPart
        part.SurfaceLight.Enabled,part.Material,part.BrickColor = true,"Neon",BrickColor.new("Cadet blue")
    end 
end
wait(30)
for _,light in pairs(area:GetChildren()) do 
    if(light:IsA("Model")) then
        local part = light.LightPart
        part.SurfaceLight.Enabled,part.Material,part.BrickColor = false,"Metal",BrickColor.new("Medium stone grey")
    end 
end
2 Likes

Sorry about not responding quickly, the second one works perfectly! Thanks