Is it possible for me to get the number amount of :GetChildren that meet a selected criteria? I want to be able to get the number of children (with #children) but only if the child is a folder.
✓ ANSWER ACCEPTED
Can I get the # of :GetChildren but only with children that meet a selected criteria?
2 answers
✓ Accepted answer
It is not possible with just :GetChildren, however you can make your own table.
function GetChildrenWithName(object, name)
local ChildrenWithName = {}
for i,v in pairs(object:GetChildren()) do
if v.Name == name then
table.insert(ChildrenWithName, v)
end
end
return ChildrenWithName
end
local Amount = #GetChildrenWithName(workspace.Folder, "Part")
You can do this with :GetChildren() and a variable
local Count = 0
for i, v in ipairs(game.Workspace:GetChildren()) do
if v:IsA("Folder") then
Count = Count + 1
end
end
print(Count)
Count should print the amount of children that meets your selected criteria
This discussion is preserved as it was. New answers, comments, and votes are closed.
