So, I’m making a pathfinding script and I’m having some big issues. sometimes they randomly just stop, and they can’t walk upstairs. allowing them to jump fixes this, but they then just start to jump in place and run into walls.
code:
local function followPath(destination)
local sucess, errorMessage = pcall(function()
path:ComputeAsync(Character.PrimaryPart.Position, destination)
end)
if sucess and path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
if blockedWaypointIndex >= nextWaypointIndex then
blockedConnection:Disconnect()
followPath(destination)
end
end)
if not reachedConnection then
reachedConnection = humanoid.MoveToFinished:Connect(function(reached)
if reached and nextWaypointIndex < #waypoints then
nextWaypointIndex += 1
LastHit = 0
humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
if waypoints[nextWaypointIndex].Action == Enum.PathWaypointAction.Jump then
humanoid.Jump = true
end
else
waypoints = nil
reachedConnection:Disconnect()
blockedConnection:Disconnect()
end
end)
end
nextWaypointIndex = 2
humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
else
warn("Path not computed! :(", errorMessage)
return false
end
end
while task.wait(.1) do
local target = findTarget()
CDMGCD += .1
LastHit += .1
SinceGoodPath -= .1
if humanoid.Health == 0 then
break
end
if target and GlobalValues.IsDay.Value == false then
humanoid.WalkSpeed = 16
followPath(target.HumanoidRootPart.Position)
else
humanoid.WalkSpeed = 10
if CurrentDestination == nil then
GetCurrentDestination()
end
if (CurrentDestination.Position - humanoid.RootPart.Position).Magnitude < 5 or SinceGoodPath <= 0 then
GetCurrentDestination()
SinceGoodPath = 20
end
local p = followPath(CurrentDestination.Position)
if p == false then
print("Forced Move")
GetCurrentDestination()
followPath(CurrentDestination.Position)
end
end
if LastHit > 5 then
nextWaypointIndex += 1
LastHit = 0
print("Hit Reset")
end
end
if you want a clip or any more code please say so, feel free to use the code as well