How can I teleport an entity to a random entity?

How can I teleport an entity to a random entity? - Person Holding Can With Blue and White Knit Sweater

I made a command that, by all Minecraft logic, should work. My command:

/tp @e[name=NameA] @r[name=NameB]

I need it to teleport NameA to a random entity, which is named NameB. Instead, it says:

The entity UUID provided is in an invalid format

How do I make it do what I want it to do?



Best Answer

The error typically occurs when no targets were found, meaning either no entity existed with a name "NameA", or no player existed with a name "NameB".

If your @r selector is intended to target non-player entities, you'll need to specify the type parameter as otherwise it will only target players:

/tp @e[name=NameA] @r[type=!Player,name=NameB]



Pictures about "How can I teleport an entity to a random entity?"

How can I teleport an entity to a random entity? - Close-Up Photograph of a Can
How can I teleport an entity to a random entity? - Yellow Haired Woman in Brown Hat Illustration
How can I teleport an entity to a random entity? - Yellow and White Labeled Box



How do you teleport a certain entity?

Players who want to move mobs to their character's position or move their character to the mob's position can use the following commands:
  • "/tp @e[type=mobtype] @p" will teleport mobs of a certain type to the closest player (usually you).
  • Typing "/tp @p @e[type=mobtype]" will move the player to them.




  • Minecraft Command Blocks: Randomized Teleportation of Entities around an Entity or Location




    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Anna Shvets, Tima Miroshnichenko, Alexander Sergienko, Alexander Sergienko