Pathfinding stuck after function fired

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Perfect PathFinding GUI

  1. What is the issue? Include screenshots / videos if possible!

Pathfinding works perfect, but sometimes just runs into walls and gets stuck
Here how it goes:

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Didn’t help much

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local plr=game:GetService("Players").LocalPlayer
local char=plr.Character or plr.CharacterAdded:Wait()
local hum=char:WaitForChild("Humanoid")
local root=char:WaitForChild("HumanoidRootPart")
local service=game:GetService("PathfindingService")
local mouse=plr:GetMouse()
local waypointz={}

local function onCharacterAdded(newChar)
char=newChar
hum=char:WaitForChild("Humanoid")
root=char:WaitForChild("HumanoidRootPart")
end

plr.CharacterAdded:Connect(onCharacterAdded)

local function AddWaypoint()
local point=Instance.new("Part", game.Workspace)
point.Name="WP88871"
point.Position=root.Position
point.Anchored=true
point.Transparency=0.35
point.CanCollide=false
point.Size=Vector3.new(1, 1, 1)
point.BrickColor=BrickColor.new("Bright Red")
table.insert(waypointz, point)
end

local function Navigate()
for i=1, #waypointz-1 do
local startp=waypointz[i]
local endp=waypointz[i+1]
local path=service:CreatePath()
path:ComputeAsync(startp.Position, endp.Position)
if path.Status==Enum.PathStatus.Success then
local points=path:GetWaypoints()
for _,v in ipairs(points) do
if v.Action==Enum.PathWaypointAction.Jump then
hum.Jump=true
end
hum:MoveTo(v.Position)
hum.MoveToFinished:Wait()
end
else
print("Failed finding a path. Please rebuild the waypoints.")
return
end
end
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

3 Likes

you should pass an Agent table to the PathFindingServive:CreatePath() method

2 Likes

How do i use Costs in it? Never used them.
Or which settings and what do they mean?

2 Likes

costs make you able to make your NPC move on certain materials or prefers to walk on a certain material than the others , you need to pass it as the last argument in the AgentTable just like this :- {["AgentRadius"] = x, ["AgentHieght"] = x, ["AgentCanJump"] = x, ["AgentCanClimb"] = x, ["WaypointsSpacing"] = x, Costs = { Ground = 1, Water = math.huge }}
this will make your NPC walk on every material except water and if possible not on ground too , you can add any material to this the bigger the number is the more your NPC wonot walk on this material

2 Likes

Question: have you enabled a property in Workspace called ’ PathfindingUseImprovedSearch’? It is currently disabled, but it should fix your problem.

3 Likes

this will enable the new pathfinding algorithm this will improve path quality but it may not fix the problem

3 Likes

i’ll try, thanks for replying!

1 Like

THANKS!!! It really helped me.

1 Like

i am glad to hear that , also you can use PathFindingModifiers and set the “Label” property to like “Cool Material” and then you can use this “Cool Material” in the costs table

1 Like