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

Is there a way to change the color of multiple parts at once?

Hello. I have a model called paintparts. There are a bunch of parts called paint. I want to change the color of them all through a script without having to write a code for every single one of them. Is there a more efficient way to change the color of them?

2 comments

0

Thanks!

1 answer

✓ Accepted answer

Yes, it's called a loop.

local model = workspace.somemodel;
local color = BrickColor.new("Red");

local HB = game.RunService.Heartbeat;
for _, child in pairs(model:GetChildren()) do
	child.BrickColor = color;  -- Set the color
	if(_==0) then HB:wait(); end -- Wait every 10 iterations, Instead of each iteration, so it changes all the part's colors faster but won't lag if the model has a very large number of parts. 
end 

http://wiki.roblox.com/index.php?title=API:Class/Instance/GetChildren

1 comment

1

Wow! I didn't know you are on this site! Thanks for the answer!

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