Hello, Joshua, and welcome. Thank you for formatting your code properly.
In future posts please give us more information of what you need help with.
I’m not sure if LUA requires indents, but if not, you should include them anyway, to increase readability. However, here is what I can see off the top of my head:
Line 3: You should check for an enemy with an if-statement before you check the distance to an enemy.
Line 6: In order to end the first if-statement before starting the second one, you need to place and
Line 6 again: Get rid of the
enemy in this line.