Title. I have tried with multiple servos of mg996r variety and ms18 so I dont think its the servo being broken. I also tested the arduino and its running blink fine.
Heres my code and connections. I've also tested using an outside powersource for more power.
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
You should not power a servo from the 5V output of the Mega. You may damage the Mega and/or the computer connected to the USB port.
Even the small servos can draw more current than a standard USB port can provide.
Use an external 5V source for the servo.
When using an external supply, make sure that the supply ground is connected to the Mega GND
Use a separate power supply for the servo, capable of providing at least 2.5 Amperes per MG996R servo, and don't forget to connect the grounds. The Arduino 5V output cannot be used to power servos.