Hello! So I have been fighting with pathfinding for a solid amount of time and found out that ‘SetNetworkOwnership’ could perhaps fix the issue, but I guess not for me? I have tried these ways so far:
NPCmodel:SetNetworkOwnership(nil)
NPCmodel.PrimaryPart:SetNetworkOwnership(nil)
for _,basepart in pairs(NPCmodel:GetChildren()) do
if basepart:IsA("BasePart") then
pcall(function()
basepart:SetNetworkOwner(nil)
end)
end
end
nothing works, and no more different tutorials, help please? I am trying to make pathfinding for it to not be laggy/stutter.
You cannot set the network owner of a Model. Instead, you will have to go through every descendant that is a BasePart.
I wrote a module for this that you can use:
local function setNetworkOwnerOfBasePart(basePart, networkOwner)
local success, errorReason = basePart:CanSetNetworkOwnership()
if success then
basePart:SetNetworkOwner(networkOwner)
else
-- Sometimes this can fail, so throw an error to prevent
-- ... mixed networkownership in the 'model'
error(errorReason)
end
end
local function setNetworkOwnerOfModel(model, networkOwner)
for _, descendant in pairs(model:GetDescendants()) do
-- Go through each part of the model
if descendant:IsA("BasePart") then
-- Try to set the network owner
setNetworkOwnerOfBasePart(descendant, networkOwner)
end
end
end
local function setNetworkOwner(instance, networkOwner)
if instance:IsA("Model") then
setNetworkOwnerOfModel(instance, networkOwner)
elseif instance:IsA("BasePart") then
setNetworkOwnerOfBasePart(instance, networkOwner)
else
warn(instance.Name .. "'s network ownership cannot be modified.")
end
end
return setNetworkOwner
This module throws an error if it fails to set the network owner.
Setting the network owner of every child will not work for NPCs that have hats, since a hat inside a character can also contain a BasePart.
That error just means that the npc model is somehow connected to an anchored part or is anchored in itself. Just add a print function before setting the network owner so you can see which part is erroring in case whatever is anchored isn’t obvious
I have checked it. Every basepart in NPC model errored, none of them are anchored nor welded to another part. Do you have an idea on how it could be fixed perhaps?