I’m working on an enemy NPC for my game and made this script that’s supposed to follow the closest player. Once that NPC is a certain distance from the player it should attack them. If walking takes too long, it stops moving and uses a ranged attack. If it find that magnitude between player and NPC is too far, it exits the loop shown in code and restarts the full code loop so it checks if there’s another nearer player to go after.
The problem is that sometimes MoveToFinished doesn’t fire, and NPC ends up standing in front of the player until it’s there long enough for ranged attack to fire. This loops for as long as the player stands still. When I jump or move in a way that doesn’t cause this, it starts attacking me with melee attacks until I move in a way that breaks MoveToFinished again.
I looked for solutions but can’t seem to find any similar problems. Previously used MoveToFinished:Wait(), but had same problem.
Let me know if any additional information is needed.