I am trying to create NPCs that attack a player when it comes within a certain range, but the problem is having multiple NPCs causes lag to spike in-game. I have tried to reduce lag by disabling certain humanoid action types, such as swimming and the stuff that isn’t generally needed for an NPC that follows a player.
The problem is that all the scripts that I used to make the NPC works uses while loops, which is very resource heavy.
Is there any alternatives to using while loops when scripting NPCs?