Should I do npc movements on the client?

So I recently read a topic on how to optimize npcs when I read these 2 parts I got kinda confused:

This is a suggestion that gets thrown around a lot, but it’s true. The server should handle all the NPC logic . You shouldn’t waste resources animating or handling other visuals of your humanoid on the server. It’ll get expensive really fast!

The idea here is that the visualization of an NPC’s movement can be done on the client

Does this mean I have to do moveRemote:FireClient(player, pos) on the server, and then when the client receives it, it will move the npc to that position? Or am I not understanding something here?

No. I believe visualization of movement refers to the like animations that show movement. You handle all the movement logic on the server and then animate on the client.

1 Like

In this case, movement is referring to visualising their movement (animations, effects and the like), not actually moving around the NPC. Actually moving the NPC is logic and should be done on the server, but their animations can be done on the client.

You can handle actual NPC movement on the client though. In the case that you have an implementation where a server-side NPC is just pure data, then the client would also need to hold the responsibility of moving the NPC towards the position the server has down.

4 Likes

Are there any tutorials that can show me how to animate them on the client?

Not necessarily, since this is a more niche optimisation idea and isn’t observed by a lot of games since it’s much more convenient to have the server handle them. It’s not as hard as you think: you’ll just need a handler that applies animations across registered NPCs. For example, CollectionService can register NPCs (tag them) and a function can go over tagged NPCs to set up their animations.

3 Likes

So it won’t optimize them very much if I do make my own custom “client-sided” animator?

By niche I mean that it’s not something widely done. Ideally the client should be handling anything and everything visual, including animating other objects. The optimisation benefit is that the server isn’t spending resources trying to do intermediate movements and has more to spend on more important tasks.

1 Like

Decided to make my own custom animator, and it worked! :slight_smile:

Thanks for your help.