How do i get a number of a model's children

like for example:

i got the children of a player.

and i wanna know how many children he has but in a form of a number

how do i do something like that?

1 Like

I’d personally use a for loop function that will gather the children and count up the variable:

local model = game.Workspace.MODEL_NAME
local parts = 0
for _, i in pairs(model:GetChildren()) do
	parts = parts + 1
end
1 Like

Hello. That’s a perfectly valid solution, but you could also use the length operator. GetChildren returns a table, so you can call “#” on it to retrieve the length of the table, i.e. the number of children.

In your use case, it could look like this:

local num_of_children = #player:GetChildren()
2 Likes