Setting Network Ownership to all players

So I want to know how I can set the ownership to all players.

image

Client:

script.Parent.SetNetworkOwner:FireServer()

Server:

local model = script.Parent

local function setNetworkOwner(model, owner)
	for i,v in ipairs(model:GetDescendants()) do
		if v:IsA("BasePart") then
			local success, errorReason = v:CanSetNetworkOwnership()

			if success then
				v:SetNetworkOwner(owner)
			end
		end
	end
end

script.SetNetworkOwner.OnServerEvent:Connect(function(player)
	setNetworkOwner(model, player)
end)

But the problem is that if a player joins, the whole model only works for the player that joins.

Not possible, and if you consider what networkownership actually is and does, its obvious why.

What is it about the model that only works for the player that joins?

Well, the client script only works for the local player and so if a player joins, that client script would run and fire the remote event so the server can set it to that player.

So what else should I do?

Then you have to think about structuring it differently. Set the network ownership based on who’s closest to the part, or have the clientscript just work entirely differently. You could also use tags and have a localscript running from all players that then gets the model through the tag.

It’s hard for me to say what the best or easiest way would be, when I don’t know what the localscript or the model entails, or why you’ve made it work the way it does in the first place.

1 Like

Can you elaborate on this? You are thinking of a solution (something with network ownership) without defining the actual problem beforehand.

The problem is that I’m using all client script to stop the lag because I’m using a lot of tweens.

It wont work because model is the player you need to set the ownership too and owner would be the model im pretty sure. I dont really use the second parameter that often too know what it is but im pretty sure its an empty variable.

Yeah, I’m redoing the whole thing so it can work better.

Why are you redoing the whole thing? Its just 2 things that you got mixed up.

More than that. :sweat_smile:

image

Had to add a lot of remote events.

Oh that’s what you meant…

Yeah that definitely needs some optimization and reworks to it.

Yeah but It wouldn’t cause that much lag.

Then why do you need to rework it?

Because all the code was in one client script.

What’s wrong with that?

I don’t really see an issue that would make you have to do that unless you have a bunch of stuff in there for multiple different purposes.

Also I wouldn’t really consider that reworking the entire thing. I would only consider it organizing it.

A part can only be network-owned by one player. When you set network owner, it changes it to swap to another owner.

1 Like

That is incorrect. It can be set locally by all players.

Edit: what I meant by locally was have the object that you want set to all players is have the part anywhere other than workspace and then have a local script move the location of the part into the workspace.