Star Formation
Stars are not true stars until they can fuse hydrogen into helium. Before that point, they are called protostars.
The sudden burst of light made by a new star blows away much of the nearby gas cloud. However, it can leave enough material behind to form a number of planets.
After stellar ignition, the star becomes relatively stable. This happens because the inward pull of gravity is balanced by the outward pressure from nuclear fusion.
Stars shine for many millions of years but do not last for ever. A star like the Sun will shine for around 10 billion years. After formation, they go through several stages which we call the life cycle of a star.
You can see what is happening in a bit more detail in this simulation.