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

I am making a piggy type of game and Ai pathfinding script broken. How can I fix it?

Asked by 3 years ago

I am making a piggy form of game and my Ai pathfinding script is not working any way I can fix it? Here the script:

local Scientist = script.Parent
local humanoid = Scientist.Humanoid

local PathfindingService = game:GetService ("PathfindingService")

local function getPath(destination)
    local path = PathfindingService:CreatePath()

    path:ComputeAsync(Scientist.HumanoidRootPart, destination.Position)

    return path
end 

local function walkTo(destination)
    local path = getPath(destination)

    for index, waypoint in pairs(path:GetWaypoints()) do
        humanoid:MoveTo(waypoint.Position)
        humanoid.MoveToFinished:Wait()
    end
end

while true do
    walkTo(workspace.destination)
    walkTo(workspace.destination2)
end
0
it would be pretty nice if you could tell us the error and which line it's on di5z 11 — 3y
0
its actually saying there is no error but he is not moving. jtath120 2 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

**Try This Maybe******

local larm = script.Parent:FindFirstChild("HumanoidRootPart")
local rarm = script.Parent:FindFirstChild("HumanoidRootPart")

function findNearestTorso(pos)
    local list = game.Workspace:children()
    local torso = nil
    local dist = 100000 -- distence for seeing player
    local temp = nil
    local human = nil
    local temp2 = nil
    for x = 1, #list do
        temp2 = list[x]
        if (temp2.className == "Model") and (temp2 ~= script.Parent) then
            temp = temp2:findFirstChild("HumanoidRootPart")
            human = temp2:findFirstChild("Humanoid")
            if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
                if (temp.Position - pos).magnitude < dist then
                    torso = temp
                    dist = (temp.Position - pos).magnitude
                end
            end
        end
    end
    return torso
end
0
thx but how would I change that for my model which is scientist jtath120 2 — 3y
Ad

Answer this question