Minecraft – How to assign players in MC to a scoreboard team automatically when they join

minecraft-commandsminecraft-java-editionminecraft-java-edition-server

I am yet again needing some help with making my Minecraft: Hunger Games map and in order to teleport each player to their podium, I set up a group of 24 command blocks setting them to teleport each team to each podium, for example:

/tp @a[team=P1] x y z, /tp @a[team=P2] x y z

But what I need is something to automatically assign a person when they join the server to a team, but each person must join a different team and I mustn't have two people in the same team.
Any suggestions on how I may accomplish this?

Best Answer

I have needed something similar in the past. The downside is it isn't very compact as you need 1 command block per team. All you need is an impulse command block and chain command blocks.

The command you put in the command blocks is

/scoreboard teams join <team name> @r[team=]

The @r[team=] targets everyone who isn't on a team. Later when the game ends you can run the command

/scoreboard teams empty <team name>

to remove all players (offline and online) on that team.