The pilot light will not stay lit if the thermocouple is bad.
The thermocouple is a safety device on the gas appliance that senses heat from the pilot flame and when the thermocouple does not sense any heat the gas is shut off to prevent gas buildup and an explosion.
A bad thermocouple can cause your pilot light to go out and not stay lit.
If your pilot light is staying lit but the gas appliance is not firing up then it could be your gas valve that works by way of a solenoid.
Sometimes those solenoid gas valves get stuck and tapping on them can sometimes get them to work.
But sometimes you need to replace the electronic solenoid gas valve for the gas appliance to work properly.