I’m currently thinking about making a Defend the Statue type game, and I was wondering how you could make an AI system that handles 200 npcs without lag, that all are able to pathfind and attack. Is this possible? I’ve done something like this before a long time ago when I was young, but it started to lag after around 50 npcs. Any tips appreciated
I don’t know how capable you are as a scripter, but there are three main things I would recommend.
- Custom pathfinding
Roblox pathfinding can be pretty heavy sometimes, so you either have to make each npc use the pathfind as little as possible, or make your own pathfinding cutting as much not needed features as possible. But probably The best thing you can do is node based pathfinding (node based pathfinding is very fast), that would the npcs use and only in cases the nodes wont find path to the target, use the classic pathfinding. - Replace humanoid instances
Roblox default humanoids are pretty heavy, and may lag in large numbers. You dont need many features the humanoids have, and replacing the only important ones (like hum:MoveTo()) shouldn’t be that hard - Dont make the whole thing on server
I am not saying to pathfind on client or something like that, but even just playing the animations on client instead on the server will help. Basically try to have the client do as much work as possible (for things that can’t be exploited ofc)
If all of theese are too hard for you to make, you can atleast raycast from the npc to its target everytime before you pathfind, and if there’s no obstacle, just use the :MoveTo() function to the target instead of pathfinding
Usually, these statue games have a defined path. Instead of using PathfindingService you can make blocks that act like nodes and use :MoveTo(). PathfindingService should only be used in cases where there’s an undefined path previously or there’s a lot of defined paths (but always with your own custom support).
Also, if the statues have animations, there’s no reason for them to be played on the server, as this will make at least two computers have to handle the animation (server and clients, instead of just the clients) PLUS the network ping might not make it accurate.
In addition, as it was previously mentioned, humanoids have states that might not be necessary (just like I mentioned before with pathfinding service) so you could handle the humanoid entities on the client and the server would just render a simple invisible part, as an example… or you can try these solutions:
@Sarlex0 covered it up, but I made this reply to explain to you why.