Magnetic clues help explain how elements form in stars