6DOF Robotic Arm using Arduino Uno and 6 Tower pro Servos (MG996R )

A schematic, showing how the servos are connected to the power supply and to the Arduino is essential.

If, with a simple sweep program, some motors go from 0 to 180 and back, and some rotate at varying speeds and directions, the problem isn't the code. The problem is that some of the motors are servos (position can be controlled) and some are variable speed electric motors (only speed and direction, not position, can be controlled).