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?

4 comments

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.

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

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

0

I think that is as good as it's gonna get. Thank You!