:MoveTo() not moving enemy to left or right?

So my enemy code works fine, the enemy will chase the player when in sight and range and will start attacking the enemy when within attack range. So in the attack range code I decided to add a block of code so that when they first enter combat with a player they will have a random chance to start blocking first and if they do I want the enemy to start moving left or right a random amount of studs. However the code run fine and it does print either “move left” or “move right” but the :MoveTo() line seems to fire but the enemy just doesn’t actually move left or right? I am unsure why that is.

enemy.Bindables.Block:Fire("Begin")
					if (math.random(0, 1) == 0) then
						
						print("Move right")
						enemyHumanoid:MoveTo(enemyHumanoidRootPart.CFrame * CFrame.new(math.random(5, 10), 0, 0).Position)
						enemyHumanoid.MoveToFinished:Wait()

					else
						print("Move left")
						enemyHumanoid:MoveTo(enemyHumanoidRootPart.CFrame * CFrame.new(math.random(-10, -5), 0, 0).Position)
						enemyHumanoid.MoveToFinished:Wait()

					end
					enemy.Bindables.Block:Fire("End")
1 Like

Had this problem when trying to make an NPC to walk backwards. Although I never found out the problem, I think it has to do with your NPCs pathfinding, and the npcs humanoid still has AutoRotate on.

But maybe you can make two parts, one at left, one at right, weld it to the HumanoidRootPart then just call the :MoveTo() function on those parts?

I have tried making a part and moving the enemy to that part but they still do not move with no error output

You cant multiply a vector3 with a CFrame.

enemyHumanoidRootPart.CFrame * CFrame.new(math.random(5, 10), 0, 0).Position