Hey, Developers!
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!
If you don’t understand something, sorry but I use google translator lol
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.
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.
the problem is that the server is positioning the pets
so lets go over the order of operations
the client presses the W key
the client moves the character forward
the client send its characters new position to the server (this can take some time depending on how good the players connection is)
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)
the server positions the pets to the players old position
the server send this new position to all players in the game (this can take some time depending on the players network speed)
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