how do second generation stars form?

A star gets old and its hydrogen fuel is depleted. Heavier elements are created and these fuse and release lots of energy and the star explodes. A nebula is formed and there are plenty of examples of these in the galaxy.
The problem is, these hydrogen poor, heavy element rich balls of gas somehow become the birthplace of new stars. Gravity should be pulling the heavier elements in first and the hydrogen in last.
Where does all the new hydrogen come from if it was all used up in the first place?

First: the hydrogen isn’t all used up. When a star goes supernova much of the hydrogen in the outer layers of the star is still unburned.

Second: “Gravity should be pulling the heavier elements in first” - no, all objects fall at equal rates regardless of their density. Light elements and heavy elements fall at the same rate.

Also, as I understand it, many of these first-generation stars explode in an area with gas and dust (a nebula) already surrounding them. The shock wave of the expelled stellar material may help to compress this surrounding mass to give a new star a little kick start.

Well, when a first generation mommy and daddy star love one another very much…

A star, in its lifetime, doesn’t use up all, or even most of the hydrogen it’s composed of. The hydrogen at its core is fusing, but most of the hydrogen in the outer layer just sits around providing the pressure that makes the core fuse and the bulk of that is still there when the star goes nova.

Add to that that a new star is unlikely to be make of the exact same material as the original star in the first place. The process is more like the nova compresses nearby gas to the point where it gets dense enough that it collapses under gravity to form a new star (albeit impregnated with some material from the original star).

Compared to how much hydrogen and helium there is in the universe, the amount produced by stars is very small. Almost all hydrogen is unfused, and almost all helium is primordial, with all stellar activity since the big bang being a small correction.