Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a way for me to place children in a table?

Asked by 5 years ago
Edited by User#24403 5 years ago
local options = {}

table.insert(options,game.Players:GetChildren())
table.insert(options,game.Workspace.Clones:GetChildren())
table.insert(options,game.Workspace.NPCs:GetChildren())

for _, name in pairs(options) do
    print(name.Name)
end

I want to add all of the players, NPCs, and Clones in my game into a table. The NPCs and Clones are all in folders in the Workspace. How do I add all of these values to the table? Is there any way I can slightly tweak my current script, or will I need to do for loops for each category (Players, NPCs, Clones) adding each player, NPC, and clone into the table?

0
Don't use GetChildren on Players, instead use GetPlayers. "...will I need to do for loops for each category (Players, NPCs, Clones) adding each player, NPC, and clone into the table?" Yes. User#24403 69 — 5y
0
Can I compress the script and combine all of the for loops into one? e.g. for _, name in pairs(game.Players:GetPlayers(),Workspace.Clones:GetChildren(),Workspace.NPCs:GetChildren()) do CelestialDesigns 2 — 5y
0
No, pairs only takes 1 argument. How would that even work anyways? what about for _, tbl in ipairs(options) do for _, item in ipairs(tbl) do print(item); end end User#24403 69 — 5y
0
I think that is as good as it's gonna get. Thank You! CelestialDesigns 2 — 5y

Answer this question