I’ll probably implement a Level of Detail like system where you can see the NPC in full, then it has no animation, and then it just doesn’t render at all if it’s too far away.
In the meantime, I’ll probably work out how to do occlusion to hide NPCs from players if they can’t see them.
coroutine.resume(
coroutine.create(
function()
while wait() do
if npc.PrimaryPart:GetNetworkOwner() ~= nil then
npc.PrimaryPart:SetNetworkOwner(nil)
end
end
end
)
)
Or even using Heartbeat for something like this, because while wait() sucks.
Yeah, that would work. Not sure what the performance gains would be like but I’d imagine it’d help. Not sure if it needs the wait() call at all though since this is running in a coroutine however yielding is probably a good idea now that I think about it.
Make sure you use the “custom wait” in the devforum thread I linked, as the one that Max used was, although efficient, not as performant as os.clock() which has much higher decimal precision
While I’m glad my module is being recognized, You are probably better off connecting your code to the Heartbeat event, as that’s specifically the usecase it’s tailored for.
Also, as far as I’m aware, you just have to call Obj:SetNetworkOwner(nil) once, no? why a loop?
This should not occur. Are you anchoring the primary part by any chance? Anchoring and unanchoring an object will set it’s network owner back to “Auto”. Also, have you tried setting the network owner of every basepart in the model to nil, i.e not just the PrimaryPart? I’ve never experienced this issue prior.
I’m not explicitly anchoring anything myself, which is why I’m so confused. I also tried what you stated (setting every BasePart explicitly) but it also did not work.
I tried the custom wait and at high NPC counts it causes Studio to hang and reach its execution limit. Max’s wait works fine and seems to be holding steady.
To be honest it’s probably my fault, I’m misusing wait() heavily already.
About 100, which isn’t that many considering I ran it with 1000 before without any execution limit issues (of course very low framerates which is inevitable).
Just dragging in the model, configuring to 1 NPC, removing the loop, and then inserting:
repeat wait() until npc.PrimaryPart:GetNetworkOwner() ~= nil
error("Network owner isn't the server anymore!!")
After doing so, just walking close to the NPC is enough to cause it to switch network owners.
Although, if I disable assets from being loaded onto the NPC, the network owner no longer switches when approaching. I wonder if attachments are treated differently when it comes to network ownership since they don’t have an Anchored property.