[LUA] Stillness in Motion Help

Hi, I need some help with the "Stillness In motion " level.
Thanks;
Here is my code;

loop
local enemy = self:findNearestEnemy()
local distance = self:distanceTo(enemy)
if distance < 5
then self:attack(enemy)

if distance enemy > 10
then self:shield()
self:moveXY(40, 35)
end 
end 
end

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 end there.

Line 6 again: Get rid of the enemy in this line.

Thanks, appreciate it.