Network Ownership
In a Roblox game, all non-anchored parts are “physically simulated” — they can fall, bounce, float in water, etc. All of these things are handled automatically by Roblox so you don’t have to write your own physics engine.
When a Roblox game runs, several computers/devices are involved. To divide the work of calculating physics, Roblox automatically assigns parts to either the server or to a client. In general, if a part is near an in-game character, its physics will be calculated by that player’s device; otherwise it will be calculated by the server. In either case, the server or client that calculates a part’s physics is called its owner.
Since physics updates must be sent over the network, there’s a small delay between when the owner makes the physical changes and when the other devices see those changes. Normally this delay isn’t too noticeable, but issues may occur when part ownership changes.
Example: Projectiles
Imagine a player is shooting an object at another player.
Problem
As the object travels through the air, it will get far from the shooter and ownership will switch to the server. Once the object gets close enough to the target player, it will switch ownership to the player. Even with a good network connection, there may be a tiny delay and visible “hop” when the object’s owner switches.
Solution
Manually set ownership of the projectile to the server using SetNetworkOwner(). This ensures that the owner does not change, preventing visible “hops.”
SetNetworkOwner() and its partner function GetNetworkOwner() must be set on the server side. Clients are not allowed to change ownership settings in a LocalScript.
Your script
In your script, the NPC networks owner is changing from client to server, which will make it stutter a few times, delaying it's time to get to the destination.
We can use :SetNetworkOwner
, to prevent it from stuttering.
Put this at the top of your script
1 | if script.Parent.HumanoidRootPart:CanSetNetworkOwnership() then |
2 | script.Parent.HumanoidRootPart:SetNetworkOwner( nil ) |