During The Great War the German Spring Offensive or Kaiserschlacht had a great advantage.
The allies were tired and depleted. The Americans weren’t ready. The Germans had more men, guns and planes.
So why did they fail?
I've answered this very question over here a few years back; explaining that the Germans didn't have much of a strategic advantage, especially when it came to the other collapsing fronts in 1918 for the Central Powers, and the Spring Offensive was more like a Hail Mary that failed rather than it being some make-or-break moment that would've decided the war.
Mostly, it was for the same reasons that no previous breakthrough attempts on either side had worked: on the Western Front, the defensive was far easier to manage than the offensive. You know where your defenses are, the artillery has better ranging on targets, and your supply lines are more secure. In spite of the impressive armaments the German Army was able to muster, they still had to fight for every inch of blasted ground. It is a testament to the sheer impenetrability of the Western Front that even with all that, they were still turned back.
Of course, there's a bit more to it, and each side had their own advantages and disadvantages.
As you say, the Allies were exhausted. The Americans weren't present in full force, and both European allies had issues with mutinies. But this wasn't a static state of being. The French were undertaking some major industrial buildup, under the direction of first Nivelle and then Pétain. They were beatable, but it wasn't simply a matter of tipping them over. The techniques used by the Allies had also greatly advanced during the war, particularly their artillery. By the end of the war, the Allied artillery was able to consistently outperform the German guns, most importantly in a counterbattery role. Artillery was the most deadly weapon used in the war, and the Allies used it to great effect. Combine that with an industrial buildup that ended the harrowing shortages of shells from the early war, and you have a recipe for carnage.
The Germans were also no prize fighters themselves. They were feeling the effects of the British blockade, and there were shortages of everything. They were the first country in the world to nationally adopt daylight savings time to preserve coal. The '16-'17 winter was known as the "Turnip Winter" for the shortage of food. Their allies were barely limping along and couldn't themselves aid in supply. Certainly they had an influx of manpower and armaments from the now victorious Eastern Front, but this was a one time thing. This materiel was irreplaceable, there would be no reinforcement once it was used up. They had a single shot at winning the war, and Ludendorff bet it all on black.
To the offensive itself, it came in multiple smaller operations. The first of these, Michael, was a major blow to the Allies. If the Germans had been able to follow up with further, similarly devastating defeats, history may have gone the other way. But here the lack of resources hampered them. The second operation, codenamed George, was scaled back massively once the Germans saw the receipt for operation Michael. Instead, operation "Georgette" was launched to lesser cost but also lesser effect. Then the next one was softer. And the next one was softer. And the next one was softer. By the end, they couldn't even push the Allies back a step let alone miles upon miles.
The Allies were tired and depleted but they weren't that tired and depleted. The Germans had more materiel but they didn't have that much more materiel. But the Allies, with howevermuch difficulty, could replace losses that the Germans could not.