When you want to rotate, use a variable to save the target roation value.
Then use another bool variable, if it's true, start rotating towards the target value.
For example in function
var rotation_speed = (target_rotation - rotation) / 100
rotation += rotation_speed
if abs(target_rotation - rotation) < rotation_speed:
rotation = target_rotation
needs_rotate = false
It's a sample code, don't copy paste the whole thing. Create variables and name them, set a different rotation speed by changing the number "100", etc.