Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

0

Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.