PathfindingService bug?

Hello, Developers to I was messing around with PathfindingService and I occured a weird bug well it seems bug to me, I am trying to move npc with PathfindingService and it works really fine, but when I get near the npc its starts glitching you would understand it better when I will show you the video below.

Script

local sp = script.Parent;
local Humanoid = sp:WaitForChild("Humanoid");
local HRP = sp:WaitForChild("HumanoidRootPart");
local PathfindingService = game:GetService("PathfindingService");
local Workspace = game:GetService("Workspace");
local WalkTo = Workspace.Point;
local Path = PathfindingService:FindPathAsync(HRP.Position,WalkTo.Position);
local WalkTo = Path:GetWaypoints();


if (Path.Status == Enum.PathStatus.Success) then
	for i,v in next,WalkTo do
		Humanoid:MoveTo(v.Position);
		Humanoid.MoveToFinished:Wait();
		if (v.Action == Enum.PathWaypointAction.Jump) then
			Humanoid.Jump = true;
		end
	end
end
1 Like

This could possibly be occuring because of Network Ownership?

If Network Ownership is set to auto, as soon as a player gets near an unanchored object, the ownership is transferred to the player.

2 Likes

I’m not really sure, but I believe it’s because the waypoints are positioned 4x4.
Edit: You could check if the NPC is 4 studs or closer to the player, then move the NPC to the player.

I don’t know if that’s true or not, but I really would like to hear what would staff say.

How would that affect the NPC, though?

Theoretically…

The script is probably on the server, since the client can’t see the script, the client assumes that the NPC is not supposed to move which could be the reason why the NPC starts lagging when the player is near. In other words, the client and server is not agreeing on the NPC’s position.

3 Likes

So should I test it with localscript?

In the meantime while the staff hasn’t said anything, try setting the NetworkOwnership of the parts of the NPC to the server by using Part:SetNetworkOwner() in a for loop. It wouldn’t hurt to try since you could always undo this.

Edit:
Doing this on a local script will cause replication issues.

I believe he only has to set it once to nil?

At the client’s side, it doesn’t work.

Edit: It only did this
image

The API page specifically says :SetNetworkOwner()

Network Ownership

As I’ve stated in my previous reply

Edit:
To test my theory on the network owner, create a script on the server that will iterate through the NPC

for i,v in pairs(NPC:GetChildren()) do
    if v:IsA("Part") or v:IsA("MeshPart") then
        v:SetNetworkOwner()
    end
end
4 Likes

Yes, I just did that now I am testing it.

2 Likes

And Instance of player in brackets right?

No, just leave it as :SetNetworkOwner() so it will set the owner to the server.

3 Likes

You could just use the Part’s base class, BasePart, to check the class. This will catch all parts rather than a specific type of them. Also; there is a chance that parts are not immediate children of a character, such as accessories. In this case, you’ll want to use GetDescendants instead of GetChildren to catch everything.

for _, part in pairs(NPC:GetDescendants()) do
    if part:IsA("BasePart") then
        part:SetNetworkOwner(nil)
    end
end

If you want to take that a step further, you can make a custom handler function that will set the network ownership of existing parts and any new descendants that get added.

Good to catch network ownership though. Not just for performance, but for security reasons as well. I remember not having a care in the world about network ownership and how it wasn’t a huge topic until it became apparent that it’s usage is important. Also prevents exploiters from tampering with NPCs if ownership is passed to them.

3 Likes