1998 Ford Ranger - Speedo off and on

My 1998 Ford Ranger speedometer only works when it is cold and then only works a short time. I know of another ranger that has the same problem. any suggestions?

The next time the speedo stops working, give the top of the dash a sharp slap.

If the speedo starts working, replace the instrument cluster.

Tester