function Intermission() for i, player in pairs(Playing) do table.insert(G.Group1, player.Character) print(G.Group1[1]) end end Intermission()
(Might've rambled a little so just skip to the question to get straight to the point)
There's so much I'm trying to understand. If I could at least figure out why my for loop I have set up won't run I'll actually start to see some progress for once. I know the function activates; it's not there anymore but I did have something get printed to the output just to see if the function was even starting (it was outside the for loop, anything inside the for loop will not run). Not sure if I'm just ignorant and using the for loop wrong, but any help is appreciated. I've been trying to figure this out for a very long time, I've tried so many things lol.
My Problem
So what I'm trying to do is a lot more complicated than what it looks like, but I'm pretty determined to figure this out without asking for too much help. I'm doing this sort of step by step.
I'm hoping to be able to randomize teams into groups of 5, 3 people per group by the end of all this. Now I haven't really thought about figuring that out yet. I'm just trying to figure out how to put player's characters into a table in general. The code above is supposed to go into Players, iterate through each player and place them into a table called Group1 (That table is actually also in another table called Teams; did that for organization and because there is two other tables/groups but not sure if that's a good idea or if it is a possible issue) .
And to help you understand my code a bit, the variable Playing is local Playing = game.Players:GetChildren()
Question
To sum things up, how could I put the player's characters into a table? Is the way I'm doing it even a vaild way? And why is the for loop getting ignored in the function?
The way you're doing is a very correct
, however your only problem
is that you defined Playing
as the list of players
in the game and you never
updated it, so it's just a table of the players that are in the game whenever you defined
it, thus, what you need to do is
function Intermission() for i, player in pairs(game.Players:GetPlayers()) do table.insert(G.Group1, player.Character) print(G.Group1[1]) end end Intermission()
That's it, hope I helped, please let me know if you have further questions!