Stars create new elements through a process known as hot fusion.
Essentially, they get so hot that they create a new stage of matter. Rather than solid, liquid, or gas, the core of stars burn so hot that matter becomes plasma. Rather than dancing around rapidly as whole atoms like they do as gases, atoms now begin to be sort of ripped apart into smaller particles and smash into one another.
This means that the atomic nuclei (composed of neutrons and protons) are ripping apart and smashing back together inside of stars, which means that they're constantly forming and destroying atoms. Due to the chaotic nature of this process, many of these new atoms have a greater number of particles than the helium and hydrogen atoms the star formed from.
Elements are defined by the number of neutrons and protons you find in the atomic nucleus of that element. So new elements are made when helium and hydrogen atoms fuse together, combining the neutrons and protons they already have because the intense heat of the stars sort of "melts" them together.
I am oversimplifying a little bit here, but this is the general process that creates new elements within stars.