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

How to make this function affect all selected parts at once?

for i,v in pairs(light:GetChildren()) do
				local start = v.MainLight.Color
		         local End = selcolor
		
		for i = 0,1,.1 do
			wait()
			local color = start:lerp(End,i)
			v.BrickColor = BrickColor.new(color)
			v.Color = color
		end

	end

That's my code and it works but I want all the parts to change colour at the same time, not one after the other.

https://gyazo.com/40be1e6c8d5c7225cb90039d32c8a2cb

I don't want to union them since my system to change the colours allows you to change each individual part's colour or all of them at once.

1 answer

✓ Accepted answer

A for i loop will stop any code from running below it until it is finished reaching it's goal. To stop this, place the loop inside a spawn function:

for i,v in pairs(light:GetChildren()) do
                local start = v.MainLight.Color
                 local End = selcolor
	spawn(function()
	        for i = 0,1,.1 do
	            wait()
	            local color = start:lerp(End,i)
	            v.BrickColor = BrickColor.new(color)
	            v.Color = color
	        end
	end)
    end

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