I'm trying to make an enemy that follows the player, the problem I'm having is that when the enemy is chasing the player, the pathfinding script will create a path, and will have to finish walking that path before making a new one, which the result can be found here.

This is my current script:

local service = game:GetService("PathfindingService")
local humanoid = script.Parent.Humanoid
local torso = script.Parent.HumanoidRootPart

while true do
	wait()
local finishPosition = game.Workspace.MovingPart -- Player to follow
if finishPosition then
local path = service:ComputeRawPathAsync(torso.Position, finishPosition.Position, 512)
local points = path:GetPointCoordinates()
for p = 1, #points do
        humanoid:MoveTo(points[p])
        humanoid.MoveToFinished:Wait()
end
end
end

How could I make it so the enemy follows the player even if the player moves? Thanks!

1 comment

0

ComputeRawPathAsync is deprecated, use FindPathAsync instead.