Pathfinding issue

When the path is blocked, it makes a new path but the old one still exists, i’ve tried setting it to nil etc, but it doesn’t work. any help? https://gyazo.com/e9efdb3da4c453cb1f22d1d071c34cab – what’s happening

1 Like
PFS = game:GetService("PathfindingService")
hum = script.Parent.Humanoid
torso = script.Parent.Torso
DT = workspace.DT
Path = PFS:CreatePath()
Dest = workspace.DT
local function followpath(Dest)
Path:ComputeAsync(torso.Position,DT.Position)
	
local BD
local blocked = false

local Waypoints = Path:GetWaypoints()
local WA = Waypoints.Action

	for i, Waypoint in pairs(Waypoints) do
		local WPN = Instance.new("Part")
		WPN.Parent = workspace
		WPN.Position = Waypoint.Position
		WPN.Size = Vector3.new(1,1,1)
		WPN.Anchored = true
		WPN.CanCollide = false
		WPN.Shape = Enum.PartType.Ball
		WPN.Transparency = 0.5
		WPN.Color = Color3.fromRGB(0,255,0)
		WPN.Material = Enum.Material.Neon
		
	if Waypoint.Action == Enum.PathWaypointAction.Jump then
			hum:ChangeState(Enum.HumanoidStateType.Jumping)
			WPN.Color = Color3.fromRGB(255,0,0)
		end
		
		BD = Path.Blocked:Connect(function(BlockedNode)
			if blocked == false then
				blocked = true
			print("Blocked")
			BD:Disconnect()
				Path:Destroy()
				followpath(Dest)
				wait(0.1)
			end
		end)
	hum:MoveTo(Waypoint.Position)
	hum.MoveToFinished:Wait(1)
	end	
end
followpath(Dest)```

You will need a cancel path function using break like this other post I helped with:

i don’t exactly see what you mean, i’ve tried reading the script and intergrating what parts i thought was the fix but none works, i probably put them in incorrectly. is it possible to show an example of what you mean?

also i don’t know what you mean by breaking or returning the function, i haven’t really done anything on that subject

any resolve i try just ends up in the AI not moving at all or still getting blocked by the part