MG996R servos are big power hungry servos. As Tom suggested, it's not a good idea to power any servos from an Arduino's 5V regulator but sometimes you can get away with it if you use a small servo and you don't drive the servo past its physical limits.
Unfortunately the sweep example uses endpoints which are outside the range of many servos.
I have a couple suggestions (besides not powering a servo from the Arduino's regulator).
Use "writeMicroseconds" instead of "write" (or use microsecond values with "write"). The servo "angle" rarely agrees with the values used with the "write" command so it's really a meaningless number. By using microseconds as the unit at least the number corresponds to some real world value (the length of the pulse). You also get much better precision using microseconds.
Set the servo's position before attaching the servo. This keeps the servo from slamming against an endstop. Use endpoints appropriate for your servo rather than the default values.
I posted a couple links to videos of a recent joystick/servo project here. By controlling the servos with "writeMicroseconds" and ramping the speed of the servo, I thought I was able to smoothly control the servos. I've attached the code I used to a post in that same thread. There's an example of how I think servos should be initialized in that program. The program also shows how to set alternate endpoints when attaching the servos.