You only find a single enemy at the very start of your code execution.
Read it out loud:
- You define pickUpCoin.
- You find the nearest enemy.
- You define attackEnemy.
- You start a while-true loop.
- You call attack enemy
- You check if enemy exists.
- You attack enemy.
- You call pick up coin.
- You find nearest coin.
- You check if coin exists.
- You move to the coin.
- Repeat (while-true loop)
Look at step #2.