Help needed: Player character gets damaged every time it's in the vicinity of an enemy

The intended behaviour is: When player is in the radius of the enemy, it starts shooting at it every few seconds. However, the shooting seems to be triggered every time the player character changes its distance from the enemy, while still remaining in range. How can I fix this?

https://pastebin.com/dyFfBnwJ