hello i was creating a pathfinding script but i have a problem
each time it moves to a waypoint, theres a slight delay
my script:
local humanoid = script.Parent:WaitForChild("Humanoid")
local pathfinding = game:GetService("PathfindingService")
local path = pathfinding:CreatePath()
local waypoints = nil
local currentwaypointnumber = 1
local function PathFindTo(destination)
path:ComputeAsync(script.Parent.HumanoidRootPart.Position, destination.Position)
waypoints = nil
if path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
if currentwaypointnumber ~= 1 then
currentwaypointnumber = 1
end
humanoid:MoveTo(waypoints[currentwaypointnumber].Position)
end
end
humanoid.MoveToFinished:Connect(function()
if waypoints ~= nil then
if currentwaypointnumber < #waypoints then
currentwaypointnumber = currentwaypointnumber + 1
humanoid:MoveTo(waypoints[currentwaypointnumber].Position)
else
waypoints = nil
currentwaypointnumber = 1
end
end
end)