How do I make an NPC follow a player a certain distance back?

Hello everyone,

humanoid:MoveTo(player.Character.HumanoidRootPart.Position)

So I have this code to make it so an NPC follows the player, but I don’t want it to follow them too closely. I want some space between them so it’s not like they’re zombies. Is there a way to keep the rotation facing the player with this code and follow them while maintaining x amount in studs back from them? Thanks!

CFrame.lookAt(npcprimarypart, whattolookat) for the player facing, and I think I found a pre-existing topic that may help

Thank you for your response. Unfortunately the topic you posted did not help as there were no formulas for an offset between the player and NPC. What I want is very simple- I want the same effect as

humanoid:MoveTo(player.Character.HumanoidRootPart.Position)

Just with an offset of x studs between the player and NPC in terms of space, but the rotation should be toward the player. Should I use LookVector for this? I know you can multiply CFrames in order to do this, but I don’t know how it works with Vectors, it doesn’t seem to work.

couldnt you just say humanoid:MoveTo(player.Character.HumanoidRootPart.Position) - 50 or something along those lines? I know the NPC wont be right behind the character but it should be able to give you some space

yes this would work, although you’d have to replace -50 with -Vector3.new(5,0,0) since position uses Vector3 and not just one number

I tried doing:

humanoid:MoveTo(player.Character.HumanoidRootPart.Position - Vector3.new(0,0,-5)

Like you advised guys, but it’s not a great solution because it only works when you’re facing one direction, but as soon as you change to the other direction the NPC will end up 5 studs beside you instead of behind you because the z and x planes don’t change so they’re either behind you or beside you depending on where you are according to the z plane. Thanks for your answers and the help.