Cause of check engine light?

So my check engine light came on the other day, and I went to autozone to get the code. I was told that it was either the tps sensor or the ecm(did not know what this stood for). I left autozone and field up with gas, then I noticed that the engine light was out. Anyway the light came on 2 days later, so I stop the engine and remove the gas cap and light goes out again?? I have heard that has caps can cause a check engine light to come on, but thought it was a different code. I had the tps sensor changed a few years ago when the check engine light came on… not sure if this is related?? also the vehicle is a 1999 toyota tacoma.
any suggestions?
thanks in advance

Rather than telling us the (questionable) “diagnosis” from the guy at Autozone, it would be really helpful if you posted the actual code(s) that they found when they scanned your OBD system.
Did you get the actual code(s)? The format is similar to “P0123”.

The code was p0120. Lists probable cause as faulty tps or faulty ecm.

ECMs rarely go bad.
On the other hand, TPSs do need to be replaced in some cases.

This truck needs to be checked by a competent mechanic who will check and diagnose properly, rather than just “throwing parts” at it.

I understand that it needs to be diagnosed by a mechanic…but there sure seems to be a connection with the gas cap??

Replace the gas cap if you think that’s the cause. It might help. What have you got to lose, except a few dollars for a new gas cap?

Toyota’s of this vintage have complicated systems that capture vapors from the gas tank. They are sensitive to faulty gas caps. Check your cap if is not a Toyota branded cap it could very likely cause a check engine light. Generic caps are not as good as Toyota brand caps so if in doubt go to a Toyota dealer and buy and new cap and see if it makes a difference.