Justice, the awesome NPC system

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.

4 Likes

Also, why does the download have the notepad app??? Or is that just me?

1 Like

I feel like a more efficient way would be:

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.

2 Likes

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.

1 Like

You probably have your associations messed up for .rbxm files. Just drag it into Studio to load it.

2 Likes

https://twitter.com/CloneTeee1019/status/1264764207498657792

2 Likes

Oh. That is definitely a massive performance gain.

I’ll switch to fastWait for the next version.

2 Likes

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

1 Like

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?

3 Likes

Nada.

I tried this before and the engine kept overriding the owner to be the client, even though it should’ve stayed on the server. I wish I knew why.

1 Like

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.

1 Like

The behavior of :SetNetworkOwner actually sets the BasePart and all connected parts network owner to nil, so that wouldn’t be necessary.

2 Likes

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.

1 Like

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.

I can’t seem to replicate your issue. Do you have an isolated place file with no scripts, just the NPC model to showcase the issue?
image

By “high NPC counts”, how high are you referring to? If this is an issue with the module, I’d like to address it.

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).

Somehow I got pinged here.

2 Likes

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.

Dragging anchors the NPC… :stuck_out_tongue: