For _,v in pairs + while true do

im trying to make parts flash rainbow when a value is true but only one of them changes colour because its looping through the for loop

local speed = 1
while script.Parent.RainbowMode.Value == true do
	for _,v in pairs(script.Parent.Parent:GetChildren()) do
		if v:IsA('BasePart') then
			for i = 0,1,0.001*speed do
				v.Color = Color3.fromHSV(i,1,1)
				wait()
			end
		end
	end
end

help plz thanks

Coroutine it

local speed = 1
while script.Parent.RainbowMode.Value == true do
	for _,v in pairs(script.Parent.Parent:GetChildren()) do
		if v:IsA('BasePart') then
			coroutine.wrap(function()
				for i = 0,1,0.001*speed do
					v.Color = Color3.fromHSV(i,1,1)
					wait()
				end
			end)()
		end
	end
end

Oh and you need some sort of delay since you’re going to crash since tehr’s no external wait in the while loop

1 Like

more like internal
the yield would be inside the loop so it is internal not external

1 Like