Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED] How to fix stuttering Npc lag in pathfinding?

Asked by 4 years ago
Edited 4 years ago

I see a lot of pathfinding lag and NPC stuttering while running the game. Although, it doesn't happen when I run it. So, I think its a Roblox created lag. So, how can I fix it?

01-- Get Pathfinding Service
02local pathfindingService = game:GetService("PathfindingService")
03 
04-- Variales For NPC Humanoid Torso And Destination
05local humanoid = script.Parent.Humanoid
06local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")
07local destination = script.Parent.Parent.Target.Position
08 
09-- Create Path Object
10local path = pathfindingService:CreatePath()
11 
12-- Compute A Path
13path:ComputeAsync(body.Position, destination)
14 
15-- Get The Waypoints Table
View all 29 lines...

And also I made some changes looking to other forums..

01-- Get Pathfinding Service
02local pathfindingService = game:GetService("PathfindingService")
03 
04-- Variales For NPC Humanoid Torso And Destination
05local humanoid = script.Parent.Humanoid
06local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")
07local destination = script.Parent.Parent.Target.Position
08 
09-- Create Path Object
10local path = pathfindingService:CreatePath()
11 
12-- Compute A Path
13path:ComputeAsync(body.Position, destination)
14 
15-- Get The Waypoints Table
View all 34 lines...

But the problem in second script is that the NPC move one step and waits for 2-3 sec and move another step.

Please help.

1 answer

Log in to vote
0
Answered by 4 years ago

I fixed the issue myself by setting Network Ownership of the NPC to nil, which is to the server!

Ad

Answer this question