-
What do you want to achieve? Fixing stuttering on my pathfinding system
-
What is the issue? It stutters way too much
-
What solutions have you tried so far? searching it up but can’t find a good solution
So basically I made this pathfinding system where an npc moves around to random parts within a folder. But whenever it’s moved to a few parts the system suddenly starts stuttering way too much and it will only walk one waypoint per 5 seconds or more.
Here a video:
robloxapp-20230419-1157504.wmv (2.2 MB)
Here the script:
local finish = nil
local pathparts = workspace.Folder:GetChildren()
function start()
finish = pathparts[math.random(1,#pathparts)]
print(finish)
local pathservice = game:GetService("PathfindingService")
local path = pathservice:CreatePath()
path:ComputeAsync(script.Parent.HumanoidRootPart.Position,finish.Position)
local waypoints = path:GetWaypoints()
for e,v in pairs(waypoints) do
script.Parent.Humanoid:MoveTo(v.Position)
script.Parent.Humanoid.MoveToFinished:Wait()
print("waypoint")
if e == #waypoints then
start()
print("reached part")
end
end
end
wait(6)
start()