Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How could i fix this?

Hello i made a script that turn on and off multiple surface lights that works but the thing is that they don't turn off at the same time, they turn off one after another which is not what i'm trying to do. How would i fix it to where they all turn off at the same time.

while true do
	for i,v in pairs(script.Parent:GetChildren()) do
		if v~= script then
		v.Bulb.SurfaceLight.Enabled = not v.Bulb.SurfaceLight.Enabled
		wait(0.1)
		end
		   end
		end




1 answer

✓ Accepted answer

Your problem is the wait inside the for loop.

You have to wait outside of that loop for the lights to change simultaneously:


while true do
	for i,v in pairs(script.Parent:GetChildren()) do
		if v~= script then
			v.Bulb.SurfaceLight.Enabled = not v.Bulb.SurfaceLight.Enabled
		end
	end
	wait(0.1)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.