I wasn't sure on this one, so I looked it up and found a result for it. Full thread is here.
01 | local function GetDescendants(root, classes, tab) |
03 | for _, class in pairs ( type (classes) = = "string" and { classes or "Instance" } or classes or { "Instance" } ) do |
04 | for index, child in pairs ( pcall (game.IsA, root, "Instance" ) and root:GetChildren() or { } ) do |
05 | if ( { pcall (game.IsA, child, class) } ) [ 2 ] = = true then |
08 | GetDescendants(child, class, tab) |
14 | for _, v in pairs (GetDescendants(game)) do |
From the person who answered: "root is the starting instance. It is not included in the returned results.
(i.e. GetDescendants(workspace) would not pass back a workspace reference)
classes: Are you looking for something in particular? (i.e. "Script" or "Part")
You can pass a classname as a string (i.e. GetDescendants(workspace, "Script"))
You can pass multiple classnames in a tabke (i.e. GetDescendants(workspace, {"Script", "Basepart"}))
In general, you don't initialize tab."
I'm not going to lie, I'm not 100% on this one, and I don't know what you need it for, but there you go.