Question regarding SetNetworkOwner()

I have a script that controls NPCs on the server side. I want them to always be owned by the server. However, sometimes they randomly become owned by the client, because their “NetworkOwnershipAuto” is set to true (I never did it, roblox automatically did that). How can I disable “NetworkOwnershipAuto”?

This property was true:

But this function doesn’t accept parameters:

So how can I stop roblox from automatically deciding the ownership of the part?

Set the network ownership of the NPC to nil when it is first created. That way, it automatically should disable SetNetworkOwnershipAuto.

2 Likes

What do you mean by first created? The NPC model is stored in ReplicatedStorage. When I use it, I cloned it from Replicated Storage and put it into workspace.

When it’s cloned, and you set it’s network ownership with BasePart:SetNetworkOwner(nil), it essentially stops others from changing it. So if you remove BasePart:SetNetworkOwnershipAuto(), then it should not set it automatically.

1 Like

To set a Part’s network owner to the server, you’ll need to use Part:SetNetworkOwner(nil) like @lavasance correctly suggested, but I’d like to mention that the SetNetworkOwner method can only be used by server Scripts. Attempting to do so in a client-sided script would result in the error: Network Ownership API can only be called from the Server.

2 Likes

How do I remove ‘BasePart:SetNetworkOwnershipAuto()’ ?

He meant to say that you should not be calling that function if you currently are.
To solve your problem, simply loop over each part in the NPC after cloning it into workspace, and then call SetNetworkOwner on each of them.

1 Like

btw if the NPC is like a player character where the parts are unanchored and has a root part set as its primary part, then using SetNetworkOwner(nil) on the primary part is enough for the whole model to be owned by the server, there’s no need to set it for every part in that case :slight_smile::+1:

@Spellwastaken

1 Like

I believe this is actually the case for any number of unanchored parts that are welded together, but yes.

1 Like

I never called set network ownership auto, but it’s already on by default for some reason

I already set every part ownership to nil aka Server, but as I mentioned, set auto is on, so sometimes it randomly just sets the network owner to client AUTOMATICALLY, how do I stop that?

Of course NetworkOwnership is set to auto by default, it is the default setting afterall.
As long as you never call SetNetworkOwnershipAuto the effects of SetNetworkOwner should be permanent.

Looping over each part of the NPC would be unnecessary, because the method acts upon the assembly of the BasePart. Basically, any Basepart that is attachment by any constraint is also affected, so welds, weld constraints, cylindrical constraints, Motor6D’s, etc

Yes, this was already clarified.

I never call SetNetworkOwnershipAuto but the effects of SetNetworkOwner sometimes isn’t permanent…

SetNetworkOwner’s effects should last until either the player leaves the server, or the part in question has been anchored. In both these cases the network ownership behavior is set back to automatic.