Command to test if players are on the same team

Command to test if players are on the same team - 2 Men in Red and White Nike Jersey Shirt Standing on Green Grass Field

I would like to test if two players (actually, slimes, but it should work the same way) are on the same team. I have two teams, Nether and Ender, and I would like to see if a given slime is on the same team as the nearest player. Is there a way to do this?






Pictures about "Command to test if players are on the same team"

Command to test if players are on the same team - Aerial View of Soccer Field
Command to test if players are on the same team - Group of Sports Player Kneeling on Field
Command to test if players are on the same team - Football Players



How do you test if a player is holding a certain item?

If you only want it to run the command the first time they join, try this:
  • Run this in the chat: /scoreboard objectives add joined dummy.
  • In command blocks on a fill clock: /scoreboard players add @a joined 0 /execute @a[score_joined=0] ~ ~ ~ [command you want to run]




  • How to calculate multiple objectives into team scores - Minecraft Command Blocks Guide




    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Robo Michalec, Mike, Pixabay, Joe Calomeni