I have a script that loops through players to change their teams, but does not work why? Here is the script:
local players = game.Players.NumPlayers for i = 1, players do p.Team = game.Teams.Eliminating print('All changed to eliminating') end
WHere is the error, and what can I replace it with?
Your loop doesn't loop throught the players. It loops the amount of players.
To get all the players we use GetPlayers()
function.
so
local players = game.Players:GetPlayers() -- the table of players
You didn't set any variable for "p"
Also to change player's team you would use TeamColor
Once we've created a table we simply need to put "#" to get the number or variables in the table.
The final script
local players = game.Players:GetPlayers() -- Creating the table for i = 1,#players do --- Getting the table's length players[i].TeamColor = game.Teams.Eliminating.BrickColor -- Changing player's team print('All changed to eliminating') end