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

How do I find how many Descendants of a certain type there are in one hierarchy?

Asked by 5 years ago

Below is the code I'm running to find the Children I need, but another aspect I need with it is finding out how many Children there are. Thank you!

local sP = script.Parent

local descendants = sP:GetDescendants()
for index, descendant in pairs(descendants) do
    if descendant:IsA("NumberValue") then
        print(descendant)
    end
end

1 answer

Log in to vote
1
Answered by
CPF2 406 Moderation Voter
5 years ago
Edited 5 years ago
local sP = script.Parent

local descendants = sP:GetDescendants()
local amt = 0

for index, descendant in pairs(descendants) do
    if descendant:IsA("NumberValue") then
        print(descendant)
        amt = amt + 1
    end
end

print(amt)
0
That's really simple, thanks! Beastlance 22 — 5y
Ad

Answer this question