Minecraft – How to teleport an entity to a random entity

minecraft-commandsminecraft-java-edition

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]