I was trying to figure out how to make so when A entity gets 10 blocks away from me It teleports to me. But I can't seem to figure It out. Can anyone help?
You can give the entity a tag and use an execute-command to test if it is in the range.
execute as @p at @s unless entity @e[tag=your_tag,distance=..10] run tp @e[tag=your_tag] @s
With your setup, it won't teleport any entities if they are within 10 blocks. Also it's teleporting the player to themself every tick, which gets annoying pretty fast.
Try an always active, unconditional, repeating command block with the command
/execute as @a[name=username] at @s run tp @e[distance=0.01..10] @s
This will teleport any entities within a 10 block radius, excluding yourself, to you. This way you aren't constantly teleported to yourself, but any entities that enter within 10 blocks of you will be. Obviously, if you want a specific entity to teleport to you, which I'm assuming you do, then add the data tag or name of the entity with tag= or name=
/execute as @a[name=username] at @s run tp @e[distance=0.01..10] @s
You can write "as username" instead of "as @a[name=username]. Aside from this the command is ok but i think the goal is not to tp every entity within a range of 10 to the player every tick.
With this command in a repeating command block a entity further away than 10 blocks with the tag "your_tag" is teleported to you.
This assumes, you only have one entity. If you have more entitys this command would be better:
execute as <username> at @s run tp @e[tag=your_tag,distance=10..] ~ ~ ~
You can write "as username" instead of "as @a[name=username]. Aside from this the command is ok but i think the goal is not to tp every entity within a range of 10 to the player every tick.
I tried your command and it didn't work, that's why I posted another solution. Thanks for the feedback on my command, I didn't realize that OP wanted it when an entity exits the range rather than enter. Good luck with your coding!
I was trying to figure out how to make so when A entity gets 10 blocks away from me It teleports to me. But I can't seem to figure It out. Can anyone help?
You can give the entity a tag and use an execute-command to test if it is in the range.
Doesn't work
I just tps It to me, I want It to do It one time when It's out of range
i have corrected my answer, try it now
With your setup, it won't teleport any entities if they are within 10 blocks. Also it's teleporting the player to themself every tick, which gets annoying pretty fast.
Try an always active, unconditional, repeating command block with the command
/execute as @a[name=username] at @s run tp @e[distance=0.01..10] @s
This will teleport any entities within a 10 block radius, excluding yourself, to you. This way you aren't constantly teleported to yourself, but any entities that enter within 10 blocks of you will be. Obviously, if you want a specific entity to teleport to you, which I'm assuming you do, then add the data tag or name of the entity with tag= or name=
Hope this helps!
Memelord and general minecraft enthusiast
With this command in a repeating command block a entity further away than 10 blocks with the tag "your_tag" is teleported to you.
This assumes, you only have one entity. If you have more entitys this command would be better:
You can write "as username" instead of "as @a[name=username]. Aside from this the command is ok but i think the goal is not to tp every entity within a range of 10 to the player every tick.
I tried your command and it didn't work, that's why I posted another solution. Thanks for the feedback on my command, I didn't realize that OP wanted it when an entity exits the range rather than enter. Good luck with your coding!
Memelord and general minecraft enthusiast
My old command (with unless) only worked if ALL entitys with this tag are out of the range.
I tested both commands (my old and new) and they worked as expected (but maybe I forgot something).
Maybe we understood the question a different way.