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

Can I get the # of :GetChildren but only with children that meet a selected criteria?

Is it possible for me to get the number amount of :GetChildren that meet a selected criteria? I want to be able to get the number of children (with #children) but only if the child is a folder.

2 answers

✓ Accepted answer

It is not possible with just :GetChildren, however you can make your own table.

function GetChildrenWithName(object, name)
	local ChildrenWithName = {}
	for i,v in pairs(object:GetChildren()) do
		if v.Name == name then
			table.insert(ChildrenWithName, v)
		end
	end
	return ChildrenWithName
end

local Amount = #GetChildrenWithName(workspace.Folder, "Part")

You can do this with :GetChildren() and a variable

local Count = 0
for i, v in ipairs(game.Workspace:GetChildren()) do
	if v:IsA("Folder") then
		Count = Count + 1
	end
end
print(Count)

Count should print the amount of children that meets your selected criteria

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