Hey everybody! So I’ve run into this same issue time and time again and it’s really stumping me. I’ve looking at scripting helpers, and here for solutions, yet I can’t seem to find anything that works. Yes, I’ve tried removing the finished event and using distance to move to the next waypoint, but that doesn’t even work. The issue, my friends is that when you create a long enough path, the AI will follow, but it will constantly stutter along the path. What in the heck is going on and how do I fix it?
Here’s my code:
local newAi = api.SpawnFunc(player)
local newAiHum = newAi:FindFirstChild('Humanoid')
newAi.Data.Target.Value = player
local newPath = pfs:CreatePath()
newPath:ComputeAsync(newAi.HumanoidRootPart.Position,player.Character.HumanoidRootPart.Position)
local waypoints = newPath:GetWaypoints()
local distance
for i, waypoint in pairs(waypoints) do
local waypointPosition = waypoint.Position
newAiHum:MoveTo(waypoint.Position)
repeat
distance = (waypointPosition - newAi.PrimaryPart.Position).magnitude
wait()
until
distance <= 4.6
end
I would stick to using the distance event. However, try setting your distance threshold to 10 and see if the stuttering happens. I can’t see much of an issue so trial and error is probably your best bet. I would go back to using the distance threshold instead of the Finished event as well.
for _, waypoint in pairs(Waypoints) do
Humanoid:MoveTo(waypoint)
if waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
Humanoid.MoveToFinished:Wait()
end
Thank you guys so much! This helped a ton. I didn’t realize I had messed up the number. I thought I put 6.5 instead of 4.5. I guess I should start reading my own code before asking questions.