Currently you can only call these methods on a single instance and if you want to retrieve children from multiple instances you either do something like
local parts = {Character.Torso, Character["Right Arm"], Character["Left Arm"]}
local allChildren = {}
for _, part in ipairs(parts) do
for _, child in ipairs(part:GetChildren()) do
table.insert(allChildren, child)
end
end
or
local InstChildren = {Character.Torso:GetChildren(), Character["Right Arm"]:GetChildren(), Character["Left Arm"]:GetChildren()}
but this would return smthn like
{
{child1, child2, ...}, --> Torso’s children
{child1, child2, ...}, --> Right Arm’s children
{child1, child2, ...}, --> Left Arm’s children
}
and you’d have to loop within a loop (both cases take 2 loops)
i think it’d be pretty cool syntactic sugar if you could just do
for _, child in ipairs({Character.Torso, Character["Right Arm"], Character["Left Arm"]}:GetChildren()) do
--> child is a child of Torso, Right Arm, or Left Arm
end
Just for update cause I am now on my PC you can use table.unpack.
What you would need to do if you want both “Left Arm” and its children is to define them separately of the arm then its children as well and just use table.unpack to well unpack the children into the main table.
for _, Child in {Character.Torso, Character["Right Arm"], Character["Left Arm"], table.unpack(Character["Left Arm"]:GetChildren())} do
--> child is a child of Torso, Right Arm, or Left Arm
print(Child:GetFullName())
end
Doing something like this would imply adding a metatable to any table that is created, which may break a lot of scripts or slow them down. I think it may be best to implement this yourself. Here is a way to implement it:
local function getChildren(instances)
local childrenTb = {}
for _, inst in instances do
local children = inst:GetChildren()
table.move(children, 1, #children, #childrenTb + 1, childrenTb)
end
return childrenTb
end
then simply call it when looping
for _, child in getChildren({Character.Torso, Character["Right Arm"], Character["Left Arm"]}) do
--> child is a child of Torso, Right Arm, or Left Arm
end