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

How to get GetChildren()'s number of children?

Asked by
4jne 18
7 years ago
Edited 7 years ago

Is there a way to get a number of children there is in a model? I want this to print 'Limit is not reached' or 'Limit is reached' depending if there are more than 10 children in a model or not. I tried doing this =D and when I was looking if someone else had this problem in forum I couldn't find the solution:

script.Parent.ClickDetector.MouseClick:connect(function(Player)
    if script.Parent:GetChildren()<10 then
        print'Limit is not reached'
    elseif script.Parent:GetChildren()>=10 then
        print'Limit is reached'
    end
end)

Error: Workspace.Model.Script:2: attempt to compare table with number

Help pls.

1 answer

Log in to vote
0
Answered by 7 years ago

You can use the '#' operator.

script.Parent.ClickDetector.MouseClick:connect(function(Player)
    if #script.Parent:GetChildren() <10 then
        print'Limit is not reached'
    elseif #script.Parent:GetChildren() >= 10 then
        print'Limit is reached'
    end
end)

0
Thanks 4jne 18 — 7y
Ad

Answer this question