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

NPC Pathfinding script isn't working as intended?

Asked by 3 years ago
Edited by Ziffixture 3 years ago

Hello! I decided to make really weird game because I was bored, and I want an npc to chase after you. I have code for it, except it is not working. No error is given. Here is the code:

function findNearestTorso(pos)
    local torso = nil
    local dist = 99999999999999999999999999999999999999999999999999999999999999999999999999
    local temp2 = nil
    local temp = nil
    local list = workspace:GetChildren()
    for x = 1, #list do
        temp2 = list[x]
        temp = temp2:FindFirstChild('Torso') or temp2:FindFirstChild('UpperTorso')
        if temp then
            if (temp.Position - pos).Magnitude < dist then
                torso = temp
                dist = (temp.Position - pos).Magnitude
            end
        end
    end
    return torso
end
local target = findNearestTorso(script.Parent.UpperTorso.Position)
local pfs  = game:GetService("PathfindingService")
    local path = pfs:CreatePath()
local waypoints = path:GetWaypoints()
path:ComputeAsync(script.Parent.UpperTorso.Position, target.Position)
for _, v in pairs(waypoints) do
    if v.Action == Enum.PathWaypointAction.Jump then
        script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
    end
    script.Parent.Humanoid:MoveTo(v.Position)
    script.Parent.Humanoid.MoveToFinished:Wait(2)
    end
0
I'm new to this site and didin't really knew how the text worked, sorry. RennDev 0 — 3y
0
are you nuts DiamondComplex 285 — 3y
0
Try to search a path finding system in the toolbox. Nervousmrmonkey2 118 — 3y
0
It looks like a zombie script. Are you trying to make it go to a player but its not working, Just search a zombie in toolbox, Copy its scripts and Folder(if there is any) and put it in your creature Nervousmrmonkey2 118 — 3y
0
didint help RennDev 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

I think I have found the issue, I did something wrong with the MoveTo script.

0
It's still doing nothing.. RennDev 0 — 3y
Ad

Answer this question