Laggy NPC animations

I have an issue with laggy NPC animations. Here is what I mean:

https://gyazo.com/c5f8de2a8f2595459353a6e08515be71

What I assume the issue is I’m using a slightly modified Roblox animation script (not a localscript) and it’s creating lag between when the server moves the NPC and then the client sees it (my Studio is set to simulate around 800 ping for testing reasons).

If I’m correct the fix would be to handle the animations on the client, but I’m not sure if that’s correct or how.

4 Likes

This could be caused by Server lag. Although you may not experience lag, the server can when you are not. It seems like the NPC lags when it gets close to the elevator. Is there something in the elevators scripts (if there are any) that may be lagging the server?

You should look for Output overloads. Sometimes, if code gets stuck i a loop with a print statement, the print statement would be firing 255,000 times a second. So make sure that is not happening. Also make sure that there are no left over “Humanoid” Instances in the Workspace. Sometimes, if you delete a Dummy, the Humanoid Instance can get stuck in the workspace. This would cause an immense amount of lag when RayTracing occurs.

You should also run the animation on the client. This makes it so if one client has 20 ping, and another client has 800 ping, It matches with the movement of the NPC.

As I said in the original post my Studio is set to simulate 800 ping. This is the root cause of the issue: high ping. I’m trying to polish it so people with high ping doesn’t have to deal with the visual lag. Players with better ping would also benefit as it would look smoother.

Also in the original post, I mentioned that, yes, I am aware that running it on the client will be smooth. I just need to know a good method.

2 Likes

Although I do not usually animate, I am pretty sure it is a good method to do it on the client.

Not every player needs to see the exact thing everyone else sees (ie. Every player does not need to be matched up the exact time and place the NPC takes a step… if that makes sense)

I also had similar issue in the past and this fixed it

This isn’t an issue with PathfindingService, it’s just an issue with delay on playing and stopping animations.

1 Like

I’m aware that playing the animation on the client is the right way to go, but I’m asking about the method.

1 Like

Then I suggest doing what @Discgolftaco231 said

2 Likes

Yep, if the player lags/looses connection with the server, server scripts won’t work for that person, while local scripts work locally, so it doesn’t matter if they player is disconnected or not.

2 Likes

As I’ve said 2 times before, I know that handling the animations on the client is the way to fix the laggy animations. I just need to know the method of doing this.

1 Like

To do that, just try to convert your NCP moving script to a local script, see if that works.

Read the post I’ve typed above ^^^

What I would do:

  • Make all scripts that don’t have a major role local, EX: NCP animations
  • While the scripts that do the heavy lifting for all the players on the server, EX: Players need to find something before time runs out.
1 Like

I’m going to resolve this issue on my own.

For those that are seeing this topic afterwards and need help, I suggest to have a client script connect to whenever the NPC needs to be seen and have it load all of the animations and and detect when they need to be played there so that the animations will be accurate to whatever the client is seeing.

1 Like