Pathfinding problem

So, I have been playing around with the pathfinding service trying to find a way to make a ‘zombie’ to follow a player without lag but also being able to go around walls using pathfinding service.

I have tried to use :MoveTo() but it isn’t able to calculate how to go around walls. Then i tried using the pathfinding service which fixes that, but i haven’t been able to mix both of them together to create a auto updating pathfinding system.

This is the script i am using:

local PathfindingService = game:GetService("PathfindingService")
 
local zombie = script.Parent
local humanoid = zombie.Humanoid
local destination = game.Workspace:WaitForChild('youchoosethe').Torso
 
local path = PathfindingService:CreatePath()
 
local waypoints
local currentWaypointIndex
 
local function followPath(destinationObject)
	path:ComputeAsync(zombie.HumanoidRootPart.Position, destinationObject.Position)
	waypoints = {}
 
	if path.Status == Enum.PathStatus.Success then
		waypoints = path:GetWaypoints()
		currentWaypointIndex = 1
		humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
	else

		humanoid:MoveTo(zombie.HumanoidRootPart.Position)
	end
end
 
local function onWaypointReached(reached)
	if reached and currentWaypointIndex < #waypoints then
		currentWaypointIndex = currentWaypointIndex + 1
		humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
	elseif reached and currentWaypointIndex >= #waypoints then
		followPath(destination)
	end
end
 
local function onPathBlocked(blockedWaypointIndex)
	print('path blocked')
	if blockedWaypointIndex > currentWaypointIndex then
		followPath(destination)
	end
end
 
path.Blocked:Connect(onPathBlocked)
 
humanoid.MoveToFinished:Connect(onWaypointReached)

followPath(destination)

The smart ai works and all but I want to make the ‘zombie’ auto update their path towards the player similar to using :MoveTo()
(If you don’t understand, basically when i use this script the zombie moves towards the humanoidroot part but when the player moves the zombie still tries to complete the goal of going towards the humroot and only when it finishes the zombie updates.)

1 Like

I went to look on YouTube and found a solution that auto updates.

1 Like