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

{SOLVED!} How to use GetChildren to count children with a specific name?

Asked by
lucided 15
7 years ago
Edited 7 years ago

If I were to use :GetChildren() to count the children with a specific name in the players backpack, how will I do so?

The tool I'm trying to count is in the players backpack (cloned from serverstorage)

1 answer

Log in to vote
0
Answered by
Filipalla 504 Moderation Voter
7 years ago
Edited 7 years ago
function countChildrenByName(name,location)
    local count = 0
    for i,v in pairs(location:GetChildren()) do
        if v.Name == name then
            count = count + 1
        end
    end
    return count
end

location is where you want to get the amount with the name

Wikipages

For Loops

GetChildren

Return

Don't forget to accept my answer if it worked! :)

Edit: ops did not see it's solved

Ad

Answer this question