How to make: Smart Chasing AI/NPC using PathFindingService

I see the glitchyness, thats probally on roblox’s side.

is there a solution to cancel the old generated path? Just like in piggy it works just fine and there is no glitchyness, Also you’ve helped me a lot :smiling_face_with_three_hearts:

Your welcome :smiley: To cancel the old generated path you can look on youtube and search “cancel move to roblox” then you can take it from there :smiley:

Or you can start a different move to which ends the old one.

Thank you! , I will mark Your Post as a Solution, Also edit the script in it :smile:

What do you mean?? (30 characters)

1 Like

So people can see the solution and the new edited script

Ohh ill post the finished script.

local whilecountdown = 0
local pathservice = game:GetService("PathfindingService")
local path = pathservice:CreatePath()
local hum,hrp = script.Parent.Humanoid,script.Parent.HumanoidRootPart --2 variables at a single line
local EndingPoint = game.Workspace:WaitForChild("EndingPoint")




EndingPoint.Changed:Connect(function()
local newPath = pathservice:CreatePath()
newPath:ComputeAsync(hrp.Position,EndingPoint.Position)
	for i,v in pairs(newPath:GetWaypoints()) do
		if v.Action == Enum.PathWaypointAction.Jump then
			hum:ChangeState(Enum.HumanoidStateType.Jumping)
		end
		hum:MoveTo(v.Position)
		hum.MoveToFinished:Wait()
end
end)

for i, v in pairs(path:GetWaypoints()) do
hum:MoveTo(v.Position)
if v.Action == Enum.PathWaypointAction.Jump then
hum:ChangeState(Enum.HumanoidStateType.Jumping)
hum.MoveToFinished:Wait()
end
end
6 Likes