How do i iterate through everything in game and their children?
I wasn't sure on this one, so I looked it up and found a result for it. Full thread is here.
local function GetDescendants(root, classes, tab) local tab = tab or {} for _, class in pairs(type(classes) == "string" and {classes or "Instance"} or classes or {"Instance"}) do for index, child in pairs(pcall(game.IsA, root, "Instance") and root:GetChildren() or {}) do if ({pcall(game.IsA, child, class)})[2] == true then tab[#tab + 1] = child end GetDescendants(child, class, tab) end end return tab end for _, v in pairs(GetDescendants(game)) do print(v) end
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.