1999 engine making a clanging sound

I have seen 3 Toyota 3.0 V-6 engines with high mileage that were clanging due to the harmonic balancer keyway being hammered out due to excess play in the timing belt and it’s possible that the 4 cylinder could develop a similar problem. If the alternator bolt is turned a few degrees back and forth and play is visible between the pulley and crankshaft that’s your problem.

Listen to this

Roderick A. Senior

Check the valve clearances.

I agree with @insightful about checking the valve lash . . . it sounds like it’s too loose

That said, adjusting valves on this engine is possible, but it’s not easy.

You measure the valve lash

Then you compare what you have, versus what you SHOULD have

Any that are out of spec requires removing the shim, measuring the shim thickness and making a calculation, to determine what shims you need to install, instead. And with all likelihood, wherever you go, they won’t have the shims in stock, and will need to order them

That does sound like a loose valve train.