My npc is jumping multiple times before reaching the next waypoint or sometimes walking backwards. I honestly don’t know why!!!
function Update() -- I have a loop that constantly updates every 1/4 of a second.
path:ComputeAsync(hrp.Position - Vector3.new(0, hrp.Size.Y/0.75, 0), ohrp.Position)
local wps = path:GetWaypoints()
table.remove(wps, 1)
coroutine.wrap(FollowOpponent)(wps)
end
function FollowOpponent(wps)
activecoroutine = coroutine.running()
for _, wp in ipairs(wps) do
if canrotate then
bodygyro.CFrame = CFrame.new(hrp.Position, ohrp.Position)
end
local check_distance = (hrp.Position - ohrp.Position).Magnitude
if check_distance > 4 then
if canmove then
if wp.Action == Enum.PathWaypointAction.Jump then
hum.Jump = true
end
hum:MoveTo(wp.Position)
hum.MoveToFinished:Wait()
end
elseif check_distance < 2 then
local dist = hrp.Position + (ohrp.Position - hrp.Position).Unit * -1 * 2
hum:MoveTo(dist)
end
end
end