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

why doesnt my humanoid follow the path made by pathfindingservice?

Asked by
Jumbuu 110
8 years ago
while true do
path = game:GetService('PathfindingService'):ComputeRawPathAsync(game.Workspace.SkullHollow.Torso.Position,game.Workspace.finish.Position,200)
points = path:GetPointCoordinates()


for p = 1,#points do
    part = Instance.new('Part')
    part.FormFactor = Enum.FormFactor.Symmetric
    part.CanCollide = false
    part.Size = Vector3.new(1,1,1)
    part.Position = points[p]
    part.Anchored = true
    part.Parent = game.Workspace.Points

end
wait(.1)
    game.Workspace.SkullHollow.Humanoid:MoveTo(game.Workspace.finish.Position)
end

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago
Edited 8 years ago

Because your ordering the humanoid to move to the position of the 'finish' spot! Rather than the current iteration in the pathfinding table.

--Define this up here just to clean up the code
local pathfinding = game:GetService("PathfindingService")
--since you use these multiple times, define a variable for ease of use.
local skhollow = workspace.SkullHollow
local finish = workspace.finish

while wait(.1) do
    --Clean this up a bit
    local path = pathfinding:ComputeRawPathAsync(
        skhollowTorso.Position,finish.Position,200
    )
    local points = path:GetPointCoordinates()
    for p = 1,#points do
        part = Instance.new('Part',workspace.Points)
        part.FormFactor = Enum.FormFactor.Symmetric
        part.CanCollide = false
        part.Size = Vector3.new(1,1,1)
        part.Position = points[p]
        part.Anchored = true
        --Move it to the current iteration in the pathfinding table.
        skhollow.Humanoid:MoveTo(points[p])
    end
end

Note: with the excessive spawning of parts, it will soon start to clutter your workspace. You may want to delete the parts using the Destroy function

Ad

Answer this question