Lua help - stillness in motion


#1

having trouble with the level “Stillness in motion” here’s my code, i get an error “end expected”

loop 
local enemy = self:findNearestEnemy()
local distance = self:distanceTo(enemy)
 
if distance < 5 then 
    self:attack(enemy)
else
    self:shield()
else 
    self:moveXY(41, 34)
    
end 
end
end

#2

You have two else clauses after your if. You probably need to either change one to an elseif or make some other change to your logic, since you can only have one else per if. This also means you have too many ends.