Network ownership for beginners - How to handle physics on the client

What is network ownership?
Let’s first ask the more simple question - What is the part’s network owner and what does it do?

Network owner is the BasePart’s physics handler. Any movements the BasePart makes, is handled by the network owner. The network owner could either be the server, or one of the players.

Let’s say we have Part in workspace. Now if a LocalScript moves the part, it will only move it for the LocalScript’s LocalPlayer.

Here’s some shapes on a client’s screen:


After moving:

As you can see, the part was moved.

Now, let’s see what the server sees:
image
The part has not moved.

This is because of the filter between the server and the client, that makes it so clients’ actions don’t replicate to the server.

So how do i make it replicate?
This is where network ownership comes in.

Let’s set the part’s network owner to the player.

local Part = workspace.Part1 -- The gray part on the image
Part:SetNetworkOwner(game.Players.Player1) -- Gives Player1 the network ownership

At first you might not notice anything.

But if a LocalScript in Player1’s client moves the part now, it will replicate to the server.
NOTE: YOU CAN ONLY SET NETWORK OWNERSHIP ON PARTS THAT AREN’T ANCHORED

So what can this be useful for?
Well, it’s quite simple really. Handling physics on the server may make the server slower and overall make gameplay more delayed and scuffed.

Let’s imagine a pirate ship game. Every player has it’s own pirate ship with cannonballs. Now imagine that the server has to handle the physics of every single cannonball fired. That would really make the server slow and even unplayable if someone spams the cannonballs.

This is where you can use the BasePart:SetNetworkOwner() function.

Whenever the cannonball is fired, the server gives the ownership to the player and makes the player handle the physics.

SERVER HANDLING PHYSICS:

CLIENT HANDLING PHYSICS:

As you can tell, the movement on the client is much smoother, and it doesn’t put work on the server.

Here’s the code if anyone is wondering:

local Cannon = script.Parent -- The cannon model
local Barrel = Cannon.Barrel -- The cannon's barrel
local ClickDetector = Cannon.Fire.ClickDetector -- ClickDetector for the cannon's trigger

local force = 1000 -- Cannon ball's velocity.

local cannonball = Instance.new("Part")
cannonball.Shape = Enum.PartType.Ball
cannonball.Size = Vector3.new(2,2,2)
cannonball.CFrame = Barrel.CFrame*CFrame.new(-Barrel.Size.X/2,0,0)



function clicked(player) -- player is the clicker
	local ball = cannonball:Clone()
	ball.Velocity = (Barrel.CFrame*CFrame.Angles(0,-math.pi/2,0)).LookVector*force
	ball.Parent = workspace
	ball:SetNetworkOwner(player) -- Set's network owner to the clicker
end



ClickDetector.MouseClick:Connect(clicked) -- Connects trigger function to trigger

CONCLUSION:
Network ownership is a good way to make the server run faster and make the players’ experiences much better.

113 Likes

You make a good point that setting network ownership to the player lessens the load on the server and makes parts more responsive/smoother, but one draw back is that the player with network ownership can now manipulate the part in whatever way they want. For example they can make the cannonball land wherever they want as an exploit and abuse this side effect.

20 Likes

I actually was just thinking about that! I was wondering how secure setting the network owner is. To my understanding, you are allowing the client to do all the work, but also replicating the work it does to the server. Does anyone know of any other way to handle things, such as tweens or lerps, on the client instead of the server?

1 Like

Hence why server checks exist. I didn’t wanna complicate things by going over it in this thread, as this is supposed to explain how to reduce lag.

Edit: Also want to add that exploiters are inevitable, i suggest adding a votekick system anyway for competitive games.

8 Likes

I don’t know why but I have a feeling that people would abuse votekick systems. I think server-sided checks are good enough depending on context.

1 Like

Not a good idea, as better players will get kicked out since no one likes them winning all the time.

5 Likes

This is a life saver, I have been using remote events for so long

5 Likes

Hello, im currently working on a custom character for my game should i set the custom character networkownership to the player? You said that “if a LocalScript in Player1’s client moves the part now, it will replicate to the server.”, Well my question is, is it safe to do player movement in a localscript and set it’s networkownership to the player, thank you. :grinning:

5 Likes