How do I "remember" a target for multiple commands?
Solution 1:
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