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

Can you store multiple parts in a variable and then change all their properties at once?

Instead of typing out

var1 = part1
var2 = part2

Etc...

Is there a way to combine then into one variable?

1 answer

✓ Accepted answer

Arrays

The best way to go about doing what you're trying to do is to store the variables and/or references in an array. This way, you can easily change the properties of the parts just by a simple iteration of the array.

I will give an example. Assume the following situation; We have two parts in workspace named "Part1" and "Part2" respectively.

We can do the following:

local parts = {workspace.Part1,workspace.Part2}

for _,v in pairs(parts) do
v.BrickColor = BrickColor.new("Institutional white")
v.Name = "This brick has been changed!"
end

The following code would change the properties of any and all bricks stored within the parts array, and change their properties based on the given code.


Useful Links

For Loop: http://wiki.roblox.com/index.php?title=In-Depth_Scripting_Guide#The_.27for.27_Statement

Tables/Arrays: http://wiki.roblox.com/index.php?title=Table

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