Hi Oliver and welcome to the forum! It is best not to comment on a topic that has been inactive for more than a month or so. Chances are, the prior contributors are no longer (not currently) active, so will not see your response.
Your intention to help is much appreciated though! You properly mention that indentation can be critical. In order to see indents here in the forum, please post all code as per this topic: [Essentials] How To Post/Format Your Code Correctly
That will turn what you just posted in to this:
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
It also provides a copy button, so we can copy/paste the code for further testing, if needed: