Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I use ROBLOX's Pathfinding Service?

Asked by
yellp1 193
5 years ago
Edited 5 years ago

I am trying to make an NPC move around and pick up parts around the map using Roblox's pathfinding service. My troubles arise whenever one of the parts is higher elevated than the npc, and when that happens the path doesn't generate at all. I have tried many solutions to fix this and currently nothing has worked. If anyone has some suggestions please tell me, and if you think I should just make my own pathfinding script, then please tell me how I should go about doing it.

while wait() do
    local Path = PathfindingService:ComputeRawPathAsync(Part0.Position, Part1.Position, 500)
    local Points = Path:GetPointCoordinates()

    for i,v in pairs(Points) do
        local Part = Instance.new("Part", workspace)
        Part.Anchored = true
        Part.Position = v
        Part.Transparency = 0
        Part.Size = Vector3.new(.5,.5,.5)
        Part.Color = Color3.fromRGB(255,0,0)
        game.Debris:AddItem(Part, .1)
    end
end
0
Well you should be posting the full code or else we can't help. I understand you want help but you should help us too. User#19524 175 — 5y
0
You shouldn't need the code. It's just the simple pathfinding service code but I will show you what it's based on anyways yellp1 193 — 5y
0
This isn't the code currently inside the NPC btw, this is just the method I used to make the path yellp1 193 — 5y
0
What do you mean by higher elevated than the npc? Pathfinding only works if it has a way to get there, so you can't expect it to just Superman fly up to wherever and get an item Professor_Boxtrot 136 — 5y
View all comments (3 more)
0
ComputeRawPathAsync is deprecated, new documentation is here https://www.robloxdev.com/api-reference/class/PathfindingService EpicMetatableMoment 1444 — 5y
0
tyler is right. npcs cannot fly. User#21908 42 — 5y
0
the problem wasn't with them flying but wrather it didn't notice that I had a jump function set up with the npc so if it was not accessible via stairs, It would completely ignore the part completely yellp1 193 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

The reason why it won't work is because your using a very deprecated version of PathfindingService and roblox refuses to run it. To keep up to date with the new Pathfinding, here is your script redone with the modern API.

while wait() do
    local Path = PathfindingService:FindPathAsync(Part0.Position, Part1.Position)
    local Points = Path:GetWayPoints()

    for i,v in pairs(Points) do
        local Part = Instance.new("Part")
    part.Parent = workspace
        Part.Anchored = true
        Part.Position = v
        Part.Transparency = 0
        Part.Size = Vector3.new(.5,.5,.5)
        Part.Color = Color3.fromRGB(255,0,0)
        game.Debris:AddItem(Part, .1)
    end
end
Ad

Answer this question