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”?
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.
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.
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.
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
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
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.
im having the same problem as spell, i think roblox just changed it.
the effects of set network owner is not permanent, and still automatically sets it to the client when i touch the part in question
this in turn makes BasePart:ApplyImpulse() stop working, which i desperately need! the only workaround i have seen is setting the network ownership every frame
Each time your part gets Anchored, it automatically resets its NetworkOwner and sets NetworkOwnerAuto to true. Just do this:
for i, p in ipairs(model:GetDescendants()) do -- go through every instance
if p:IsA("BasePart") then -- check if said instance is a basepart (part, meshpart)
p:GetPropertyChangedSignal("Anchored"):Connect(function() -- fires whenever the part gets anchored/unanchored
if not p.Anchored then -- is the part unanchored?
p:SetNetworkOwner(nil) -- if yes, set give the ownership to the server
end
end)
p:SetNetworkOwner(nil) -- set it here too since the function above won't get called instantly
end
end
SetNetworkOwnershipAutocannot be toggled no matter what. It will always automatically reset to true each time a part is unanchored.
Also unrelated, but I recommend opening a new post if you have an issue instead of going to old posts and asking there. You just may not get an answer.