The problem is within the (p2 - p1). If p1 goes below 0, this will result in a positive rotation, which is most likely not the direction you want it to turn.
Thus you must make sure that p1 is a valid, positive angle. To do so, you simply call the function like:
Tween(p1 mod 360,p2 mod 360,t)
Or better, you already wrap the angles to valid positives when you set them instead of converting them when you need them, as this would eat up useless time again.
Thus you must make sure that p1 is a valid, positive angle. To do so, you simply call the function like:
Tween(p1 mod 360,p2 mod 360,t)
Or better, you already wrap the angles to valid positives when you set them instead of converting them when you need them, as this would eat up useless time again.