Humanoid:MoveTo not functioning as intended

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to make a somewhat “Smart” NPC System where the enemies will randomly move in front of you in an arc shape.

  1. What is the issue? Include screenshots / videos if possible!

https://gyazo.com/6e345fa5c606d1fca808860db1c6e6c6
As shown in the video, my NPC moves as if I were calling MoveTo on the model instead of the humanoid, which I indeed am not.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Lots of debugging, searching the devforum and not finding any problems similar to mine, as well as a few reworks which all failed.

Important Code:

TravelTarget = function(npc,dist,rot)
	local target = npc.Data.Target.Value
	local h = npc.Humanoid
	local nc = CFrame.new(
		npc.HumanoidRootPart.CFrame.Position,
		target.CFrame.Position
	)
	local rc = nc - nc.Position
	local x,y,z = rc:toOrientation()
	npc.HumanoidRootPart.CFrame = nc * CFrame.Angles(-x,0,-z)
	
	rot = math.random(unpack(rot)) or math.random(-90,90)
	local location = (
		(target.CFrame * CFrame.Angles(0,math.rad(rot),0)) * CFrame.new(0,0,-dist)
	)
	h:MoveTo(location.Position)
	wait(0.2)
	h:MoveTo(npc.HumanoidRootPart.CFrame.Position)
	h.MoveToFinished:Wait()
end

I can confirm that the issue isn’t coming from ping which brings me to a loss.

Check this line out:

npc.HumanoidRootPart.CFrame = nc * CFrame.Angles(-x,0,-z)

Seems you’re setting the CFrame of the HumanoidRootPart.

1 Like

This doesn’t actually move the character though. All it does is rotate them because I have AutoRotate disabled.

My mistake.

Not sure what’s the issue, but I would try one of these:

  • Try commenting out the first MoveTo
  • Try commenting out the npc.HumanoidRootPart.CFrame line, just in case.
  • Try moving the humanoid to a random spot rather than near the player and see if they teleport.

Commenting out the CFrame change actually worked, but now the NPC can’t rotate to look at me. Enabling AutoRotate would mess up other feature which brings me to another loss.

You can use a BodyGyro to rotate the humanoid towards the player.

2 Likes