On a 1999 ford ranger xlt what causes the speedometer go from 60 down to 0 while driving and the abs light is on too?

I have a 95 Mazda B2300, and it does the same thing, and if you bang on the dash board, the speedometer starts working, unfortunatly fords have a lot of wiring short problems, and my ABS light too, but I don't know why. replace the sensor located on top of the differential.