The end of a star’s life depends on its mass.
Small stars die pretty quietly, becoming planetary nebulae, white dwarfs, and then black dwarfs.
Very large stars explode in supernovae, possibly turning into neutron stars or black holes.
Most of the matter in the star is blown away by the supernovae explosion forming nebulae, and what remains will be a neutron star.
The blown-off outer layers of dying stars include heavy elements which are often recycled during new star formation.
These heavy elements allow the formation of planets.