Descendants Change Color Together

Hey there!
I have a script that changes colors randomly of spotlights, but I want to get all of the lights to change color at the same time. Right now, it’s changing their color one at a time.
Here’s my script:


for index, descendant in pairs(descendents) do
	if descendant:IsA("SpotLight") then
		descendant.Color = Color3.new(math.random(), math.random(), math.random())
		wait(0.2)
	end
end

I used to use while true do, but that didn’t let it go on to the next light, and for i = 1, 10 or something
did the same thing, except it only changed one at a time, then moved on.

Remove the wait(0.2) and it’ll go at the same time

1 Like

Use a coroutine this way the loop progresses without a delay on the wait(0.2)

for index, descendant in pairs(descendents) do
	coroutine.wrap(function()
		if descendant:IsA("SpotLight") then
			descendant.Color = Color3.new(math.random(), math.random(), math.random())
			wait(0.2)
		end
	end)()
end

Yes, remove the wait (0.2) and it will work fine, you can also use TweenService to add an effect to the lights.

1 Like