I am trying to make a npc, but which detection method should I use?

Hi, I am trying to make a npc that follows you and kill you. As of now, I want the npc to ONLY attack when another enemy npc or an enemy player is in range and the npc will go back to the original spot after there are no enemies left in the region/range.

So my question is, what method of detection should I use? Region3 or distancefromcharacter or some other things I never thought of? Btw, the game is meant to have a lot of friendly npc, friendly players, and many enemy npc, enemy players.

I have tried doing while true do and constantly update the region using FindPartsInRegion3 but the “for” loop that I use to select the UpperTorso from the pile of stuff in the table is very laggy in studio and that was without any other characters inside the region.

1 Like

I am not entirely sure. I don’t think you should do distancefromcharecter though since if you are having a lot of players in your game, it would turn into a jumble

I suggest you have a look at this. I think it will help.

I think you can use Magnitude for this.

1 Like