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

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

Asked by
P100D 590 Moderation Voter
8 years ago

Instead of typing out

var1 = part1
var2 = part2

Etc...

Is there a way to combine then into one variable?

1 answer

Log in to vote
1
Answered by 8 years ago

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

Ad

Answer this question