Hi, I’m pretty new to using lua for coding, and I’m not sure how to do this.
I want to take each part (specifically named part) from the map_baseplate folder and add each to a table.
from what I know, all I’ve been able to do is this;
for part in workspace.LightingNodes.Map_Baseplate do
end
Yeah, not too great of a start. The issue im running into is now grabbing the value from it then adding to some type of list I can refrence in a local script, I could do this if they were named seperately, but they should all be named the same out of organization purposes.
Thanks for reading, and if you have any ideas im open to it.
basic idea of the file structure: Workspace > LightingNodes > Map_Baseplate > Part(x4)
Well first you need to create a table and from what I see, you are trying to attempt a for loop which is a good start but it’s in the wrong format. Then you loop through each part and insert it into the table.
local parts = {}
for _, part in pairs(workspace.LightingNodes.Map_Baseplate:GetChildren()) do
if part:IsA("BasePart") then
table.insert(parts, part)
end
end
I’ll try to explain in depth what it generally does.
Firstly, you’ll create a local variable which has a value of an empty table, and we’ll call it parts. Then we set up our for loop to iterate over all the children of Map_Baseplate using the method :GetChildren() which will really just return a table with all instances inside Map_Baseplate.
The part will be the current instance of this iteration, then just to be sure it’s a part we use :IsA("BasePart") method (which btw can be switched to just :IsA("Part"), as I don’t know what exactly are you trying to do) & if it’s indeed a part it’ll be appended to the table we created earlier.