Hi I am learning to script and I was learning from this tutorial pathfinding script but it doesn’t move the character to the ending part as it is supposed to. Can anyone help me with this?
local PathfindingService = game:GetService("PathfindingService")
local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local Path = PathfindingService:CreatePath()
Path:ComputeAsync(torso.Position , game.Workspace.endingPart.Position)
local waypoints = Path:GetWaypoints()
for i , waypoint in pairs(waypoints) do
human:Moveto(waypoint.Position)
human:MoveToFinished:Wait (2)
end
human:MoveTo(game.Workspace.endingPart.Position)
local PathfindingService = game:GetService("PathfindingService")
local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local Path = PathfindingService:CreatePath()
Path:ComputeAsync(torso.Position , game.Workspace.endingPart.Position)
local waypoints = Path:GetWaypoints()
for i , waypoint in pairs(waypoints) do
human:MoveTo(waypoint.Position)
local targetReached = false
connection = human.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
end)
local StartTick = tick()
local Timeout = 2
repeat
wait()
until
targetReached == true or (tick() - StartTick) >= Timeout
end
human:MoveTo(game.Workspace.endingPart.Position)