Why are model teleports replicating on server If it's been done on the client side?

To prevent exploits such as autofarming, I recently tried to autofarm on my own game using studio’s command bar. Basically what I’m doing is teleporting an NPC to me and then killing it. However, when I teleport the NPC to me on the client and I check the server, I see the NPC being repeatedly teleported to me. Why does teleporting a model replicate to the server from the client?

https://gyazo.com/fc2445bab9556107bbbad342d021350e

I have a feeling that It’s the script inside the NPC that is used to find the player’s humanoid and move to it however can someone tell me how I can fix that? I’m new to this. Thank you.

EDIT: I have tried deleting the script inside NPC and it still replicates to the server. I do’n’t know what I’m doing wrong?

2 Likes

i believe it’s because your player gains network ownership of the npc. that means the player can calculate certain physics for the npc when the player is close enough to the npc. this applies to other things that use physics in your game.

teleporting npc is one of the things players can do when they have network ownership. another thing they can do is break all the joints of the npc, killing it, which will be replicated to the server.

obviously you don’t want this. to fix, set the network owner of your npc’s to the server. you can do this by getting the HumanoidRootPart of your npcs and doing HumanoidRootPart:SetNetworkOwner(nil). this only works on unanchored npcs.

2 Likes

I fixed it by looping HumanoidRootPart:SetNetworkOwner(nil) and it works fine.
Thank you so much!

2 Likes

Do I also have to set network owner of all the parts connected to the NPC? ( Such as tools ) Or is it even possible to set it to the NPC? Sometimes when I do it, after awhile, they still teleport to me.

Edit: I set all the parts of the NPC to nil and it works, however when the npc is moving towards me, it’s acting weirdly… movement’s don’t seem… normal?

1 Like

it’s not possible to set ownership to the npc. when we set ownership to something, we are giving rights for that person’s computer to do physics calculations that will be replicated to the server. since the npc does not have a computer, it can’t have network ownership of anything.

players have a computer, and the server is a computer, so those are the two entities in the game that can have network ownership of something, players or the server. in this case, we want to set the network owner of the npcs to the server so players can’t lie about what exactly is going on to the npc.

an assembly is a group of parts connected by welds or motor6ds. characters, including the npc, classify as assemblies. when trying to set the network ownership of something, you only have to change the root part of the assembly to change the ownership of all the other parts in the assembly. so what’s the root part of a character assembly? well, if you guess HumanoidRootPart then we have a winner! here’s an article that explains it better.

however, depending on what you’re parenting to the npc and how you’re changing it’s accessories, certain weapons or tools you may give it might change the root part of the npc, which may be affecting the network ownership as you describe. make sure the accesories/equipment you give it are massless and unanchored, among other rules. read the article i linked for a full sense of what’s going on behind the scenes.

the reason why npc movement may seem off is because of how network ownership works. since you’re changing it to the server, the players have to wait for the server to tell them where the npc is before their client can update the npc’s position on their screen. the clients try to do some interpolating in between every time the server updates them, but it won’t be perfect because of network latency.

1 Like

Oh okay, I see. The problem was with the sword model that was welded onto the npc, it wasn’t massless so I guess it was changing the network ownership. I fixed it now, thank you!

1 Like