I'm trying to make a place filled with zombies and NPCs. The zombies will chase both players and NPCs and whenever an NPC is touched by a zombie it will turn into another zombie that will start chasing players. Problem is that using a lot of humanoids will make the game lagg a lot.
So my question is: what if i change the follow script in order to move zombies with body position and body velocity instead of humanoids ? Will i have less lag ? (Zombie health will just be an intvalue so there's no need of a humanoid)
Also consider animations - which are usually attached to humanoids - wouldn't be available for the zombies unless you can find replacement ones that use an AnimationController. (Of course, not having animations at all would be much better for lag.)
Using BodyPosition would probably not be a good idea: it would be difficult or impossible to get your zombies to move smoothly (since every scripting frame (every 1/30th of a second) you'd have to update BodyPosition.position).
If you use Body___ objects, don't forget to use BodyGyro to make their angle appropriate.
A good way to test which is better is to create both. See what FPS you get (go to View > Summary stats and look at your FPS) when you add 10s, 100s, or 1000s of zombies of the first type into an otherwise blank place. Make a script to have them constantly moving (or just put a character that they can chase in there, perhaps by going into the place and running around). Then repeat the experiment for the same number of the second type of zombie. If you're not experiencing an FPS drop, increase the number of zombies until you are. If the FPS is the same for both tests, you're using the same # of zombies in each test, and the the place is noticeably laggy, you can conclude that the difference is probably negligible.
Note that a potentially large source of lag is the logic for the zombies. If they are frequently checking the position between them and a large number of potential targets, you can cut down on some lag by having them update their target less frequently.
If you start experiencing "stutter lag" (where the place has noticeable slow-downs), whether in normal play or during your above tests, this is probably because all the zombie AI scripts are updating at once. To fix this, use a single script that controls all of them and in the loop that iterates over each zombie, have it wait() as needed (ex if you want the zombies to update once every 10 seconds and you have 5 zombies, then wait(10/5) after every zombie update. If you want 5 zombies to be updated every 0.1 seconds, then don't forget that there's a minimum wait time, so you'll need to compensate by keeping track of total time waited vs desired time waited, and if the total time waited is too high, skip the wait time for this iteration.)