Servo motor malfunctioning

I know its not the power supply because I have tested the Servo motor outside of this code before with the same power supply. I believe the problem is in the code, not the hardware. I think it has something to do with the attach command because when I take the attach command out, the servo motor doesnt move.