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

Why arent my NPC's following the pathfinding points?

Asked by 7 years ago
Edited 7 years ago

~=Overview=~
The script is an Ai, it follows mobs,i am trying to implicate pathfinding to it, I've succesfully made it so that it makes a path out of parts in the 'Pathfinding' way to the target.

**~=Problem=~ **
The script find nearest Npc and goes towards them like its saposed to, but it does not take the pathfinding path

while wait() do
    local target = findNearestTorso(script.Parent.Torso.Position)

        if target ~= nil then
        local magnitude = (script.Parent.HumanoidRootPart.Position - target.Position).magnitude                     

           print('WENUS')
            if magnitude < 5 and deb == false then
                deb = true
                script.Parent.Humanoid.WalkSpeed = 0
                script.Parent.Attacking.Value = true
                wait(.5)
                script.Parent.Humanoid.WalkSpeed = script.Parent.Settings.MoveSpeed.Value               
                deb = false
            else
                while true do

                    path = game:GetService ("PathfindingService"):ComputeRawPathAsync (script.Parent.Torso.Position,target.Position,200)
                    points = path:GetPointCoordinates()

                    game.Workspace.Points:ClearAllChildren()

                    for p = 1, #points do
                        part = Instance.new("Part")
                        part.FormFactor = Enum.FormFactor.Symmetric
                        part.Size = Vector3.new(1,1,1)
                        part.CanCollide = false
                        part.Position = points[p]
                        part.Anchored = true
                        part.BrickColor = BrickColor.DarkGray()
                        --part.Transparency = 0
                        part.Parent = game.Workspace.Points
                    end

                    script.Parent.Humanoid:MoveTo(target.Position,target)
                    --also tried script.Parent.Humanoid:MoveTo(part.Position,part)
                    wait(0.5)
                    end


            end     
        end
end 
0
Perhaps the range is too short? antonio6643 426 — 7y
0
no Faker243 43 — 7y

1 answer

Log in to vote
0
Answered by 5 years ago

Try using Humanoid:MoveToFinished:Wait()

Ad

Answer this question