0
votes

so I am writing a script that gets all players and adds them to a table. 4 players are then randomly selected and removed from the table. The players inside the table will be placed in one team, while the 4 removed are in another. At the end of the round, the table gets reset and everyone gets put back into the table, and players are picked again. In order to make things simple, I'm having players get added to the table whenever they touch the spawn Location in the lobby, this way new players, and all players after being sent back to the lobby are added back to the table.

My problem is that I'm just a bit confused on how to change the players still inside the table's team.

This is what I have, though it comes up with the error: "attempt to call a nil value"

Obviously, I'm doing something wrong, I just don't know how else to call the players still inside the table:

PlayersToTeams:GetChildren().Team = game.Teams.Fugitives

PlayersToTeams is the table, Fugitives is the team I want the players inside the table in.

1

1 Answers

0
votes

I fixed it with this function

local function splittingPlayers()

    PlayersToTeams:GetChildren().Team = game.Teams.Fugitives
end
local function ChangeTeam(team)
  for i,v in ipairs, PlayersToTeams do
    v.Team = team
  end
end