I would think there a better way to do:
if math.floor(object.rotation) == targetangle+1 or math.floor(object.rotation) == targetangle-1 then
I can't use:
object.rotation == targetangle
because object.rotation gives values such as 55.44444444444444881
It seams stupid to use an OR statement.