I am making a 1.14 minecraft minigame, and one aspect is when two players not on a team walk up to each other, they are put on the same team. I am wondering how to do this.I have included all 16 team colo(u)rs, and the team names are:

dark_red, green, dark_green, yellow, black, dark_blue, dark_purple, gold, red, aqua, gray, light_purple, blue, white, dark_aqua, dark_gray

  • Use raycasting to add a tag to a player the ray intersects. m.youtube.com/watch?v=9XWkA6bF36c Is a good resource for how to do it, and the basic command still works in 1.14.
    – Nik3141
    Apr 30, 2019 at 23:22
  • @Nik3141 i'm not sure how that would work? May 1, 2019 at 15:38
  • Do you need to do it if there are two players next to each other or looking at each other? I'll write an answer for being next to each other and then if you need looking I'll write another.
    – Nik3141
    May 1, 2019 at 16:14
  • I'm pretty sure this question was asked before, but I can't find it. If someone has a link, please post it in a comment (or contact me otherwise if you can't). May 1, 2019 at 21:06

1 Answer 1


To team players who are within five blocks of one another who don't currently have a team:

In a repeating command block:

execute as @a[team=] at @s if @a[team=,distance=1..5,limit=1] run execute as @a[distance=..5,limit=2] run team join <team name> @s

What this does is it executes as a player who has no team at that player if there is a single player within 1 to 5 blocks away who also doesn't have a team. It runs another execute function which executes as both players joining them both to a team. If you want to randomize which team they join try something like this:

Setup a scoreboard to track the current time: /scoreboard objectives add time dummy

In a repeating command block set the scoreboard to the current time: execute store result score @a time run time query daytime

In a number of similar repeating command blocks set a particular team depending on the current time: in this example green is for 1000 to 2000:

execute as @a[team=] at @s if @a[team=,distance=1..5,limit=1] run execute as @a[distance=..5,limit=2] if score @s time matches 1000..2000 run team join green @s

You'd need a different command block for each team and time.

  • 1
    TIL that "team=" is a complete selector argument. Interesting. May 1, 2019 at 21:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .