Target selectors in depth

When a command runs but nothing happens, the number one cause is a target selector that matched nobody. This page walks through the square-bracket arguments one at a time

The five selectors

All five work on Java and Bedrock. What differs between them is how many targets they return and whether mobs are included

Selector How many Mobs? When to use it
@s Always 1 Whoever runs it The most precise one — almost always what you want inside execute as
@p 1 Players only A command block that should affect whoever walked closest
@a Everyone Players only Announcements, handing out items, applying a setting server-wide
@r 1, at random Players only Picking a lucky winner or a random hunter
@e Everything Mobs, dropped items, armour stands, everything Always pair it with a filter, or it sweeps up everything in range

The biggest trap is a bare @e, because it includes players — /kill @e kills everyone on the server, not just the mobs. Always add a type filter, e.g. @e[type=zombie]

Square-bracket arguments (Java)

Append them straight after the selector, separated by commas and no spaces — a space tells the game the argument ended

Argument Meaning Example
type Filter by entity type @e[type=minecraft:creeper]
name Filter by display name; names with spaces need quotes @e[name="ราชาซอมบี้"]
tag Filter by a tag you added yourself — the most flexible option @a[tag=alive]
distance Distance in blocks; ranges are allowed @a[distance=..10]
limit Cap the number of targets @e[type=zombie,limit=3]
sort Ordering applied before limit cuts the list — nearest, furthest, random, arbitrary @e[sort=nearest,limit=1]
scores Filter on a scoreboard score @a[scores={kills=5..}]
team Filter by team @a[team=red]
gamemode Filter by game mode @a[gamemode=survival]

Writing ranges

Numeric arguments such as distance and scores accept ranges written with two dots — and this is where most typos happen

Written like thisMeans
distance=5Exactly 5 blocks away — almost nothing matches that precisely, so it is rarely what you meant
distance=..10Up to 10 blocks — this is what most people actually want
distance=10..10 blocks or more
distance=5..20Between 5 and 20 blocks

A simple rule: the side the dots sit on is the side that is open-ended

How sort and limit work together

These two always work as a pair: the game orders every match by sort, then cuts the list down to limit. Setting limit without sort gives an unpredictable result

  • @e[type=zombie,sort=nearest,limit=1] — the single nearest zombie
  • @a[sort=random,limit=2] — two random players
  • @a[sort=furthest,limit=1] — the single furthest player

In effect @p is @a[sort=nearest,limit=1] and @r is @a[sort=random,limit=1] — write the long form when you need to add other filters too

Bedrock writes these differently

The @p @a @r @s @e shorthand is identical across editions, but the names of the bracket arguments are not — which is why a command copied from a Java guide usually fails on Bedrock

JavaBedrockMeaning
distance=..10r=10Maximum radius
distance=10..rm=10Minimum radius
limit=3c=3Maximum number of targets
gamemode=survivalm=survivalFilter by game mode
type, name, tagSame namesThese three are written the same on both sides

This table covers the commonly used arguments, not the full Bedrock list. If the one you need is not here, check it against the documentation for your version before relying on it

Why a selector matches nobody

SymptomCommon cause
Runs silently with no error The filter is too narrow to match anything — for example distance=5, which demands an exact distance
Works in chat but not from a command block @p and distance are measured from the block, not from you
The command turns red at the bracket A space after a comma, or an argument name from the other edition
Mobs are affected when you only meant players You used @e instead of @a — @e counts everything that is not a block

The fastest way to debug it is to strip the arguments off one at a time until the command starts working — whichever one you removed last is the culprit

Tools that use target selectors

Other guides to read next

  • Minecraft command basics — Start from zero: how to enable cheats, where commands can be typed, and enough about selectors and coordinates to get going
  • Coordinates: numbers, ~, and ^ — Why ~ and ^ cannot be mixed, why blocks end up in the wrong place, and which form to reach for in which situation
  • Command blocks — Take the commands you generated and run them automatically — once, on repeat, or chained one after another
  • Why an old give command stops working — Legacy NBT, 1.20.5 components, and 1.21.5 components side by side — compared using commands built by the generator itself
  • Scoreboard basics — Create an objective the game tracks for you — or track it yourself from a command block — then use the score as a condition elsewhere
  • The execute command — The most powerful command in the game, taken apart piece by piece — how as differs from at, and why reordering changes the result
  • My command does not work — Work back from the error the game shows you, with the usual cause behind each one