How would I go creating module scripts for ally NPC's?

Heya there.

I’m trying to recreate a ROBLOX game called “Noobs Vs Zombies: Relish Reborn”. Anyway, I’m starting to work on the ally NPC’s that will fight for you. The issue is that I don’t know how to implement it.
I am planning on creating a module script that is responsible for spawning in ally NPC’s for respective teams via CollectionService alongside giving them weaponry and AI with other modules scripts acting as AI for the possible ally NPC’s.

Any help?

1 Like

It looks like you have this fairly well planned out. If the behavior isn’t insanely complex, I would recommend avoiding two things: behavior trees and consistent loops. Set an action, and wait until it completes before continuing. Try to only pathfind once, use (some) client side raycasting to determine when an NPC is in sight. Anything you can do to lighten the load on the server will help you. Let me know if you would like to discuss anything else!

Alright. Tell if this is a bit complex;

The majority of the NPC’s (Specifically ones that attack) uses weapons that are typically used for players. I’m planning on having a module script that holds the AI for NPC’s using ranged weapons and another for melee.

I’m also going modify the weapon so the NPC’s can interact with it such as firing and reloading by adding in bindable events.

1 Like

One of the biggest concerns when designing AI is how players will damage them. Usually for PvE, you can have client sided hit detection. If you do, you only need to store a little bit of data on the server, and all the models will be client sided. First just get the replication framework for damaging the NPCs and telling the server, along with the security aspect. For NPCs shooting players, things get a bit more complicated. If your bullets are affected by gravity, and you want the NPCs to shoot and hit a moving target accounting for the velocities and acceleration, you’ll need a lot of math and an advanced replication system. I can help guide you, and I plan on making some community resource topics in the coming weeks discussing some of this. Good luck!

The majority of the guns (Pistols, Assault Rifles, Snipers, Etc) are hitscan. Additionally, all of the raycasting is done on the server of course.

For NPCs, use the server as a double check and do the initial detection client side. The player can send in the position they hit, along with the barrel position. Ensure that both are close to the server position. That way you won’t need any server instances. I would just do the replication system first and spawning/killing first, then focus on behavior. Maybe do a module for each kind of NPC, a parent module that handles the spawning, and only a single script requiring that parent module.