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

Why isn't this pathfinding zombie moving?

Asked by 6 years ago

No matter what I try, it won't move or pathfind!

local pathfindingService = game:GetService("PathfindingService")

local root = script.Parent.HumanoidRootPart
local zombie = script.Parent.Zombie
local spawnCF = root.CFrame

function findPlayer()
    for _, v in next, game.Players:GetPlayers() do
        if v.Character then
            local char = v.Character
            if char:FindFirstChild("Humanoid") and char:FindFirstChild("HumanoidRootPart") then
                local pRoot = char.HumanoidRootPart
                if pRoot then
                    if (pRoot.Position - root.Position).magnitude <= 30 then
                        return v
                    end
                end
            end
        end
    end
    return nil
end

while wait() do
    local player = findPlayer()
    if player then
        local path = pathfindingService:ComputeRawPathAsync(root.Position + Vector3.new(root.Position.X, root.Position.Y, root.Position.Z + 2), player.Character.HumanoidRootPart.Position + Vector3.new(player.Character.HumanoidRootPart.Position.X,  player.Character.HumanoidRootPart.Position.Y,  player.Character.HumanoidRootPart.Position.Z + 2), 500)
        local coords = path:GetPointCoordinates()
        for _, c in next, coords do
            zombie:MoveTo(c.Position)
        end
    end
end

Can't seem to figure out the problem. No errors in output; help, please!

Answer this question