Is it gas or electric? Is it news or old water heater. If it is a newer water heater check and be sure the air intake filter is not clogged with dust and debri. Located around the bottom of the water heater and possibly below the main burners. If you are going to change the gas controller you need to shutoff and drain the water heater. Shut off the gas and disconnect the gas and thermocouple connections. Then counter clockwise disconnect the old controller. Install new one, reconnect the lines. Turn on the gas and check for leaks. Turn on the water heater and check for proper operation.
Get the exact replacement, shut the cold and hot water, open the hot faucet until the water stops and then close, if you have a vacum breaker remove the black plastic cover and push down on the white inside part and tape it so no air can get in, shut the gas and disconnect the gas line from the gas valve,disconnect the pilot line(if there is one using 3/8 wrench), disconnect the thermocouple ( if there is one using 7/16 wrench), disconnect the main burner tube using 3/4 wrench (this one is reverse thread),pull burner out, pipe dope the threads of the new valve and place it near by. Using a pipe wrench, unscrew the old valve until you can do it by hand but remember how many turns going out. Once you can unscrew by hand, use one hand to remove and have the other in your hand ready to screw back in. It should only girgle out like a 2 litre bottle of water upside down. Be quick but don't cross thread the valve. Screw back in the same amount of turns you did to unscrew. Be very careful not to damage the new valve with the pipe wrench. Woudn't hurt to put a rag between valve and wrench once you've got a couple turns by hand. Reconnect in reverse be careful not to over tighten aluminium tubing. Soap check all gas connections after. Depending on the water heater, it could cost as much as $300.00 for a new valve. Valve and t-stat are one piece.
If you can get the exact replacement, remove the screws that hold it in place, move it out of the way leaving all the wires connected and install the new one. Replace one wire at a time. If you get a universal replacement, make sure you know what you're doing because you may have to do a little rewiring. The new one should come with a booklet with all the different wiring diagrams. If you've never done it before, it could be very confusing or intimidating.