Minecraft – How to execute a command when ALL of the players are close enough

minecraft-commandsminecraft-java-edition

I'm making an adventure map and came to a point where all players have to be within three blocks to activate a command.

I tried using the /execute command on a repeating, always active command block but that command executed as soon as one player came within three blocks.

execute if entity @a[distance=..3] run tp @a -424.5 80.1 108.5 135 0

Best Answer

If all players are nearby, that means that no players are far away. In command form:

/execute unless entity @a[distance=3..] run <command>

But that still executes if someone is in other dimensions, you can fix that this way:

/execute unless entity @a[distance=3..] in the_nether unless entity @a[distance=0..] in the_end unless entity @a[distance=0..] run <command>

If you want the command to execute in the overworld, you have to add in overworld before run.