Minepax Chest LogoMinepax.com
Back to Blog

How Minecraft target selectors work (@a, @e, @p, @r, @s)

Minepax TeamAugust 31, 2026
How Minecraft target selectors work (@a, @e, @p, @r, @s)

@e with no filter grabs every entity inside the loaded area — dropped items, arrows still in flight, item frames on a wall, not just mobs. That's the single most common selector mistake, and it's almost always a missing type=.

The five selectors

| Selector | Targets | |---|---| | @p | the player nearest to whoever runs the command | | @a | every player | | @r | one random player | | @e | every entity — players, mobs, items, projectiles, item frames | | @s | whoever (or whatever) is executing the command |

The arguments you'll actually use

| Argument | Does what | Example | |---|---|---| | type= | filters by entity type | type=zombie, type=!player (excludes players) | | distance= | filters by distance in blocks | distance=..10 (up to 10), distance=5.. (from 5 up) | | limit= | caps how many targets come back | limit=5 | | sort= | orders results before the limit applies | nearest, furthest, random, arbitrary | | gamemode= | filters players by game mode (@a/@p/@r/@s only) | gamemode=survival | | tag= | filters by a tag set with /tag | tag=enemy |

Three commands ready to copy

Kill every zombie within 10 blocks:

/kill @e[type=zombie,distance=..10]

Teleport the nearest survival-mode player to you:

/tp @p[gamemode=survival] @s

Give glowing for 30 seconds to every player within 20 blocks:

/effect give @a[distance=..20] minecraft:glowing 30 0 true

Build these same commands — give, summon, effect — with the right target in the command generator; the target field takes @p, @a, @r, @e, @s as-is, or a custom selector with your own arguments.

Common mistakes

I used @e[limit=1] expecting the nearest entity, and got something else. limit alone doesn't sort anything. Without sort=nearest, the game returns the first entity it finds in the loaded area, which can be any of them. limit=1,sort=nearest together is what actually guarantees "the closest one."

Isn't distance=10 the same as distance=..10? No. distance=10 asks for exactly 10 blocks, which almost never matches. distance=..10 means "up to 10 blocks" — the .. before the number is what opens the range downward.

@s doesn't work inside a command block. A command block with no player context attached has nothing for @s to point to, so the command silently fails on that target. Use @p or @a in command blocks that aren't triggered directly by a player.

How do I select everyone except one person? Repeat the argument with ! in front: @a[name=!Notch] selects every player except whoever is named Notch. You can stack more than one ! to exclude several.

Does type= take more than one value? Not on its own — each type= filters a single type. For several types at once, it's usually simpler to run the command once per type than to chase a compound condition.