Minecraft – How to detect if 2 players have the same scoreboard

minecraft-commandsminecraft-java-edition

I am making a minigame when two players are needed to start an arena !
Trying with the c selector for count, but it seems that doesn't work
This is the command I used:

/testfor @a[score_arena_min=1,score_arena=1,c=2]

The arena scoreboard notes the players who joined an arena, the 1 value being for arena 1.

Command block image

Can someone give me another solution than that?

Best Answer

The c parameter is to limit the maximum number of targets to obtain rather than a minimum. For example, if there were 3 possible matches while c was set to 2, only the 2 closest would be selected. If there were only 1 target possible, then only that target is obtained.

Since you know the exact score and number of players you want to look for, you can check the command block's SuccessCount integer tag value without changing the command you're using. If it's 0, then no players were found. If it's 1, then only 1 player was found. If it's 2, then 2 (or more) players were found with that score.

Repeating > Chain > Conditional Chain

  1. The command you're currently running which will set the command block's success count appropriately.

    /testfor @a[score_arena_min=1,score_arena=1,c=2]
    
  2. Check the command block's SuccessCount value to ensure it is 2. Modify the XYZ coordinates to target the repeating block.

    /testforblock X Y Z minecraft:repeating_command_block -1 {SuccessCount:2}
    
  3. Conditional. Action to perform as a result of there being at least 2 players that matched.

    /say Starting with players: @a[score_arena_min=1,score_arena=1,c=2]