Hello there. Basically, in my creation I am trying to program a NPC AI.
Essentially, the player has a tool, which commands the NPCs.
But, I ran into many problems.
First, I request some tips on how to program NPCs better, especially complex NPCs.
Second, I have a question about NPCs: If there are about 1000 - 2000 NPCs on a very large map at once, each with their own script, how bad will the game lag?
Lastly, is there a good way for me to put a player’s tool inside of an NPC and have it use it similar to the player(I have remote events but they require things like mouse.hit which I can’t seem to get out of an npc)?
The code I have currently is really inefficient, laggy, and messy.
Thank you to those who respond or read this post 
2 Likes
I can’t really give many tips on NPC programming because it depends on where you are trying to go with the NPC. But secondly multiple NPCs with scripts won’t lag too bad if you have wait timers before the scripts activate or if you make them activate based on player distance to the NPC.
A quick question, will the NPC have the same movement-system as the player’s character? I ask this cause one thing I like to do is use Object Oriented Programming for practice and having a virtual manager that the NPC would then use. This way the NPC would have the same authority level as a player’s character the only difference is the system is controlling the NPC’s actions and what not.
@UneducatedScripter The npcs will be following at least one player each time so according to that do you have any idea how much it’d lag?
Pretty much. Let me try to explain it better. I have a flag tool. It will fire the NPCs which follow the player to “move to a place” or “attack”.
The server is controlling the NPCs based on client-side actions.
So how would you use your OOP to manage the NPCs?
If they’re following each player now that depends on if you animate all of them and how many players are in each server. Like a .io game?
if 100 players are in a server and 2000 npcs(at the very limit) how much will it lag?
I can’t really tell you that much information since the number is really high, but if most of the NPCs are local and scripted correctly with no errors lag shouldn’t be too hard depending on your computer. I would suggest making a load assets screen first.
1 Like