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

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.


This reason yours is not working is that it is testing for all the players in that area.

solution 1

If you want to execute a command if all of the players are within range. You probably need to use scoreboards. First would need to create a scoreboard.

/scoreboard objectives add PlayerCount dummy "Number of Players"

Next you either need to have a datapack function that repeats every tick or 2 repeating command blocks which perform these commands

/execute store result score PlayersInWorld PlayerCount run execute if entity @a (Stores the number of players in the world into PlayersInWorld constant)

/execute store result score PlayersInArea PlayerCount run execute if entity @a[distance=..3] (Stores the number of players in the range into PlayersInArea constant)

And finally, you test if all the players in the Minecraft world are in that spot by doing

/execute if score PlayersInArea PlayerCount = PlayersInWorld PlayerCount run tp @a -424.5 80.1 108.5 135 0

solution 2

That is a rather complex solution. Here's a much more simple one, which tests if there are no players outside of the radius rather than testing if all the players are in the radius.

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

Side Note

By using the first solution you can display the scoreboard which would help you know how many players still need to go into the area. You could also replace PlayersInWorld to PlayersRequired and set it to a specific number so that rather than needing all of the players you only need a certain amount.