Pilot lights but goes out when you release the button? That is the thermocouple. It is a thin metal rod next to the pilot flame that generates a tiny voltage when heated. That voltage holds the gas valve open. When the thermocouple fails, no voltage, gas valve closes, pilot goes out. Replacing it is one of the simplest water heater repairs. Unscrew the old one, screw in the new one, relight the pilot. Universal thermocouples ($8-15) fit most standard gas water heaters. Takes 15 minutes.