Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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?

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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
Wow! I didn't know you are on this site! Thanks for the answer! bruceywayne 35 — 7y
Ad

Answer this question