Everything is wired correctly and the sketch uploads without error but the motors only run a short time then it all slows down or stops - or processor resets.
Many people unknowingly try to power a project with a 9V PP3 type battery not realizing this type is for very low current draw applications, ie, smoke detectors and multimeters. Refer to the below linked thread for an example of this.
Here's the author's image of the circuit.
That's just too much load for that type of battery.
And here's a thread with a link to technical data describing the issue.
Bottom line: forget powering your project with a 9V PP3 battery - use multiple AAA or similar with more current capacity.