I tried to make an enemy go to the player, all though it does not work

Hey there guys. Basically I’ve been trying to make it so that an enemy comes after you after you enter It’s attack zone. Although this hasn’t worked.

So far haven’t tried anything but change the variable a bit but didn’t work. Hopefully somebody can help me out here and I can learn something new today.

1 Like

The only thing I see wrong is this line

if humanoid == xyx then

You’re trying to compare humanoid with an AttackZone. That’s not how it works.

A proper way of doing is just in the loop for the attacking enemy, have it check if the player is touching the Zone, and if they are, attack them, otherwise, stay still.

Also your thing would move to every player in the game rather than the closest one


I would highly recommend using Region3 that way you can detect the player that entered the zone and if they left, if they enter make the Enemy walk towards them, if not they go back to their original spot.

1 Like

How would I use Region3 here though. I have never used it before so maybe try putting code and like explaining what it does?

I would recommend reading about it and how you could try to add it here


I went on there, and I got the basic idea of it I guess but I have no idea what to do with it.

I did try using it but still didn’t work for you to know.

You could use the formula in the post to generate a Region3, and everytime it tries to move the enemy, check if that place’s character is in the region3 via FindPartsInRegion3, which returns a table of all the parts found, meaning you’d have to loop through that as well I believe

yeah, but how would i actually check if the player was in region3 because I tried to do that although it did not find the actual player but the other parts

How did you code look like when trying to use FindPartsInRegion3?

Sorry for late response, went to get lunch.

That code only works once, hence why it wont work properly, put the while wait() do outside and do the FIndPartsINRegion3 code inside it when it has to see if a player is in the region when attacking.

We could discuss this more tomorrow if needed as it’s night time for me