Target Selectors

This Minecraft tutorial explains all about target selectors and how to use them in game commands and cheats.

## What is a Target Selector?

A target selector is used to target players or entities in your game commands. There are 5 target selectors that you can choose from:

 @r
 @a
 @e
 @s

Let's explore what each of these target selectors do.

## Target Selectors

### `@p` (Nearest Player)

The @p target selector is used to target the nearest player in the game. The nearest player will always be the player closest to the location where the command is run.

If a command block has executed the command, the nearest player to the command block will be targeted. If you run a command from the Chat window, the player running the command will be the nearest player.

For example, you can use the @p selector with the /give command to give the nearest player 5 gold blocks:

```
/give @p gold_block 5

```

### `@r` (Random Player)

The @r target selector is used to target a random player in the game.

For example, you can use the @r selector with the /give command to give a random player 15 emeralds:

```
/give @r emerald 15

```

### `@a` (All Players)

The @a target selector is used to target all players in the game.

For example, you can use the @a selector with the /give command to give all players 2 emeralds:

```
/give @a emerald 2

```

### `@e` (All Entities)

The @e target selector is used to target all entities in the game. This includes both players and mobs in the world.

For example, you can use the @e selector with the /kill command to kill all enderman:

```
/kill @e[type=enderman]

```

Notice that in this last example, we have used `[type=enderman]` to target only enderman. This value is called a target selector argument and allows us to filter the target.

Let's explore target selector arguments further.

### `@s` (Entity executing the command)

The @s target selector is used to target the entity that is executing the command. This is often referred to as "yourself" in the Minecraft help.

For example, you can use the @s selector with the /give command to give the player who is running the command 64 tnt:

```
/give @s tnt 64

```

## Target Selector Arguments

You can use target selector arguments to reduce the number of players or entities being targeted. Here are some of the more popular target selector arguments that you can use:

A target selector argument is case-sensitive and always surrounded in [ ] such as `[type=cow]`. If there is more than one target selector argument used in a command, the arguments are separated by a comma such as `[type=cow,limit=5]`.

### Target Selector Argument Examples

Here are some examples of how to use target selector arguments.

To kill all cows:

```
/kill @e[type=cow]

```

To kill 5 cows:

```
/kill @e[type=cow,limit=5]

```

To give the 3 nearest players 64 emeralds:

```
/give @a[sort=nearest,limit=3] emerald 64

```

## Common Mistakes with Target Selector Arguments

Here are some common mistakes made with dealing with target selector arguments.

### 1. Spaces between Target Selector and Argument

Do not put spaces between the target selector and the target selector arguments. If you do, the target selector argument will be ignored.

**INCORRECT**:

```
@e [type=cow]

```

**CORRECT**:

```
@e[type=cow]

```

### 2. Capitalizing the first letter of an Argument

Target selectors are case-sensitive and are generally all lowercase. Do not capitalize the first letter of an argument. If you misspell a target selector argument (and accidentally uppercase the first letter of the argument), the target selector argument will be ignored.

**INCORRECT**:

```
@e[Type=cow]

```

**CORRECT**:

```
@e[type=cow]

```

Congratulations, you have learned about target selectors in Minecraft. Now, try a game command using a target selector.