✓ Accepted answer
The best solution to this would be recursive, so that we count objects inside of sub-models (as opposed to just direct children of the model we are talking about).
Here is our recursive statement:
#objects in model = #objects as direct children + #objects in each child
function countParts(model)
local number = 0;
if model:IsA("BasePart") then
number = 1;
end
for _,child in pairs(model:GetChildren()) do
number = number + countParts(child);
end
return number;
end
If there was a model of 5 parts in the workspace called "thing", then we could get that 5 using:
countParts(workspace.Thing)
2 comments
:IsA("Part")is more robust; especially because you can use:IsA("BasePart")and also count SpawnLocations, TrussParts, WedgeParts, etcAh ok, thank you. :)