Best way to make performance friendly enemies? (In large numbers)

I’m making a game where you shoot the enemies, these usually come in hordes on tens.
However, they seem to cause a bunch of server lag, which made me scratch my head for a couple days.

The way the system works is:
-In a single script, use a while loop (0.2 seconds) and use for i, v loop with CollectionService:GetTagged to get all the tagged humanoids.
-Check if the tag is the “Enemy” tag.
if the checks are met, do the following:
-Find a player X studs away from the enemy
-If the player is found, fire a bullet

If anyone has a suggestion on how to improve the code, please let me know

2 Likes

You can try consulting this post.

Pretty much the server just sees the NPCS as singular parts, instead of objects and leaves the client to render all the details.

3 Likes

This looks interesting, although it might solve my problem, I was hoping to get a more code oriented solution

1 Like