Lagging pet movement that make gameplay difficult

Hey, Developers! :wave:
For some time now I have been struggling with a problem in my game, the lagging pets following the player (everything is fine with animation)
The longer the server is active and the more players there are on the server, the more visible it is.

I’m uploading a video from my friend where you can see it exactly:

I use a normal script for each pet, which includes:
while wait (0.55) do - I added this to mitigate the lag, which was successful; and raycast - I do not suspect this about lags because they were also without it.

Script activity for a single player from a freshly launched server with 8 pets is about 0.6%.
Increases to around 5% when breaking a present (a way of getting coins)

I will be grateful for any information that will help me solve this problem! :smile:

If you don’t understand something, sorry but I use google translator lol

1 Like

Network owner ship is the problem I think
are the pets a model?
if so make sure they have a primary part, then put this line of code at the top of a script that is in the model.

script.Parent.PrimaryPart:SetNetworkOwner(nil)
1 Like

Yes, pets are models
image
image

Also I have the NetworkOwner function in the script in which the pet is configured and spawned:
image

So is it necessary to add what you wrote to the movement script?

no. If you have it set to player it should work. Don’t change it to server, keep it as player.

not sure what is causing this then.

are there any waits in the script causing it to delay?

there is no more waits in movement script
previously it was RunService.Stepped but the script activity was x3 higher

Hmm. It looks like the script isn’t moving the pets to the players character fast enough

Can you show your pet following script?

Animating all your Pets on the Server is really bad, Mainly if you have alot to Animate at the same time. I would advice you to control the Pet Animations on the Client - As if the Server does so, It would take alot of Memory-usage and updating it several times on the Server will make it laggy.

1 Like

If you use a continuing tween animation or a MoveTo() function its probably because 1 Script handles all the pets.

1 Like

the problem is that the server is positioning the pets

so lets go over the order of operations

  1. the client presses the W key
  2. the client moves the character forward
  3. the client send its characters new position to the server (this can take some time depending on how good the players connection is)
  4. the server gets the players new position (by the time the server gets this position this position is now the players old position because the time it took the server to get this position the payer has moved further forward)
  5. the server positions the pets to the players old position
  6. the server send this new position to all players in the game (this can take some time depending on the players network speed)
  7. each player gets the new pets position after some time and then positions the pet in the position the server told them

so as you can see because the server is positioning the pets the position is delayed

so how can we fix this

what you need to do is give the pet owner network ownership of the pets then you should position the pets in a localscript so the server is not positioning the pets but the client who owns the pets is positioning the pets

there is another method and that is each client positions the pets for all other clients but that method is a bit more difficult so ill leave that out

1 Like

Thanks, I will do and let you know if it has helped :smile: