Hi! I am trying to use pathfinding on NPCS but for some reason they lag. Yes. I set network ownership to nil and it still does not work. I can’t tell if I’m using it correctly.
Here is the script btw!
This Is The NetworkOwnership script.Parent.HumanoidRootPart:SetNetworkOwner(nil)
This is the pathfinding
function WalkTo(Position)
local pathfindingService = game:GetService("PathfindingService")
local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("UpperTorso")
local path = pathfindingService:CreatePath()
path:ComputeAsync(body.Position, Position.Position)
local waypoints = path:GetWaypoints()
for k, waypoint in pairs(waypoints) do
if STOP_01 then return end
Humanoid:MoveTo(waypoint.Position)
Humanoid.MoveToFinished:Wait()
end
Humanoid:MoveTo(Position.Position)
end
so it depends What is the lag that you are experiencing, is it going to the path Waypoint and just stopping for a brief second, or is it lagging your game.
Your code worked fine when I tested it. It might have something to do with the variable STOP_01 that might be causing the NPC to prematurely cancel walking.
I made a test AI that uses the code but I have a hunch it has to do something with the Humanoid.WalkToFinished:Wait() Because after a while the humanoid starts to stutter when walking. I think it may just be lag due to Roblox’s functions not being optimized somehow.
Maybe try a different method of telling when the humanoid is in the spot
there was one thing I forgot to do and it was set the network owner, Now it works perfectly fine, I have no idea what your issue could be, Did you set the network owner of the HumanoidRootPart?
yes I do believe that it could be an issue with the fact that Roblox Automatically sends ownership of a parts physics to the client, And with that the check is waiting for the client to respond with the new data. And there is a high chance that ping has a lot to say in this issue