Enemy/NPC player detection

There are 2 other options of detecting players behind/around the NPC.
You can create Region3s behind/around the NPC and use FindPartsInRegion3 to get the players in the Region3.
You can also create a hitbox part behind/around the NPC and use GetTouchingParts to get the players in the hitbox.

However:
Looping through players and computing the distance from them will be less expensive, as it’s just a magnitude comparison from the player’s HumanoidRootPart position to the NPC’s position. You can use Player:DistanceFromCharacter to reduce overhead from Vector3 arithmetic.

Region3s require more math operations to compute which parts are inside it, and the same goes with GetTouchingParts. Read the “How do Region3 checks work?” section on the FindPartsInRegion3 page.

3 Likes