2

Let's say I want to target the nearest player to 5, 5, 5 and teleport them to 50, 50, 50:

/tp @p[x=5,y=5,z=5] 50 50 50

but then I want to /kill them (specifically in this order). This would not work:

/kill @p[x=5,y=5,z=5]

because there may be another player there that is different.
How do I remember who I selected first to target them in multiple commands?

2

Tagging

Tagging is a way to select specific players that have the tag. They can be added or removed at any time, and multiple players can have them. We do this via

/tag @p add MyTag

and remove via

/tag @p remove MyTag

We can select everyone with a tag with the selector @a[tag=MyTag].

How to Fix This Example

First, instead of teleporting the player let's tag them:

/tag @p[x=5,y=5,z=5] add selected

We added a tag we call selected to them. Now teleport them:

/tp @a[tag=selected] 50 50 50

Now kill them:

/kill @a[tag=selected]

Now take the tag away:

/tag @a[tag=selected] remove selected
| improve this answer | |
  • When an entity is killed, it loses all its tags. When a player is killed and respawns, are their tags kept or lost? – ExpertCoder14 Nov 20 at 5:08
  • @ExpertCoder14 sorry your reply seemed to slip my eye. Tags are kept when a player respawns. – Penguin Nov 25 at 2:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.