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

1 comment
Can you please put everything inside of a lua block? It's really hard to read and fix it this way.