Detect if all minecraft players are within a certain area

I am making an minigame, and I need to detect if all players are nearby

I tried /testfor @a[r=10] but this returns true even if only one player is nearby

How can I check if all players are near?


In order to do this, you'll need to invert the check and the arguments.

Your old test: If there are any players in the radius, run the command.
Required new test: If there are any players outside the radius, do not run the command, otherwise run it.

  1. Create a scoreboard objective to store the number of players outside the radius.

    /scoreboard objectives add minigameData dummy
    
  2. Create an always active repeating command chain of 4 blocks. Inside, place the following commands:

    1. Reset the number of players outside the required range.

      /scoreboard players set #playersOutsideRange 0
      
    2. Tell everyone outside the range to add 1 to this value.

      /execute @a[rm=10] ~ ~ ~ scoreboard players add #playersOutsideRange minigameData 1
      
    3. Set a redstone block to a nearby location.

      /setblock ? ? ? redstone_block
      

      Replace the ?s with the coordinates of a convenient location nearby.

  3. Create an impulse command chain of 2 blocks. Place the starting block next to the location you specified in the last command. Place these commands inside:

    1. Test for zero players outside the range.

      /scoreboard players test #playersOutsideRange minigameData 0 0
      
    2. CONDITIONAL: Run the command.

      ...Whatever you want...
      

I ended up using /testfor @a[rm=10] to check if there were any players outside the range, then inverting the comparator output from that.

The other answers here were a bit complicated, but they got me pointed in the right direction - I had completely forgotten that rm was a thing.