i want to use both properties, the vector3 location and the part instance, which i would set as (0, 0, 3) and my player character’s root part
however, if i use MoveTo(), the npc moves rather sporadically depending on what direction i’m facing, yet if i literally set MoveToPart and MoveToPoint separately it works correctly. however, the distance between the player and the npc easily grows in distance as the player walks, which can be very problematic
Hey, it would help us out a lot if you posted your code. This makes it easier for us to understand what you’re attempting to do and spot any errors in your code.
local followie = script.Parent.person.Value --person to be following!
yourself = script.Parent --the model
local yourhumanoid = yourself:WaitForChild("Humanoid")
local them = game.Players:WaitForChild(followie)
print("funny npc script loaded")
local distance = 3
while them and yourhumanoid do
wait()
local pos = yourself.HumanoidRootPart.Position
--print(them:DistanceFromCharacter(pos))
while them:DistanceFromCharacter(pos) > distance do
yourhumanoid:MoveTo(Vector3.new(0, 0, distance), them.Character.HumanoidRootPart)
wait(1)
end
end
this probably ain’t the best script but it’s something, haha
My apologies, I didn’t realize you were trying to make a character walk. I shouldn’t have skimmed through your code. I was having similar issues a few months ago and my research lead to roblox being ‘glitchy’.
while them:DistanceFromCharacter(pos) > distance do
yourhumanoid:MoveTo(Vector3.new(0, 0, distance), them.Character.HumanoidRootPart)
wait(1)
end
use
if them:DistanceFromCharacter(pos) > distance then
yourhumanoid:MoveTo(them.Character.HumanoidRootPart.Position)
else
yourhumanoid:MoveTo(yourself.HumanoidRootPart.Position)
end
the NPC just moves right into me, which, isn’t what i intended. i’d like it if they would stand a little bit behind the player, to give them some room to move by themselves before the NPC follows
even when increased, it doesn’t work as expected. they’ll walk into the player, before stepping away for a moment, still on your tail. i even set it to 6
it’s a little better, but the NPC still takes that weird step away, and it isn’t very smooth, if that makes sense. otherwise, i guess this works, thank you!
There are a few bad practices in your code, but based on the wiki information, your MoveTo should be working fine. However, even when I tested out MoveTo(pos, part) it still wasn’t working correctly.
This code should work as expected, though. Instead of relying on the MoveTo function to find the position directly behind the character, it does it manually. Replace your while loop with this.
while them and yourhumanoid do
if them.Character then -- make sure the character has loaded
local root = them.Character.HumanoidRootPart
local goal = root.CFrame:pointToWorldSpace(distance) -- this basically finds the world coordinates of the position 3 studs behind the character
yourhumanoid:Moveto(goal)
end
wait(0.5) -- decrease this wait time to reduce choppiness
end
It only times out if no other calls are made to MoveTo after 8 seconds and the humanoid doesn’t reach its goal. The timer resets when you call it again.