I thought I'd post this solution here, in case it's of use to other folk on the forum. Recently, the speedometer on my 2002 Rav4 (4.2) VVTi 1998cc Petrol, failed. To begin with, I was driving down the motorway, and the needle went nuts, dropping to 0 MPH then coming back up to my cruising speed, on and off in quick succession.
After about 5 minutes of the speedometer needle bouncing up and down, it finally stopped altogether. After about 20 minutes of further driving, the Engine-Management light came on too, indicating a trouble code (no doubt due to the loss of vehicle speed input).
Most of the research I did on the internet pointed towards the fault being with the vehicle speed sensor, which is located in the gearbox (close to the firewall, towards the right hand side of the gearbox).
However, whilst trying to troubleshoot the issue, I inadvertently came across an article that suggested the problem could lie with water getting into a connector block, inside the vehicle. The connector block in question lives behind the driver's side kick panel, just to the right of the accelerator pedal:
Indeed, when I removed the kick-panel, and unplugged the very bottom white connector block, I found evidence of corrosion (green build-up visible in pic), and the cable was wet:
I believe in my case, the water is entering from the sunroof, and making it's way down the driver's side windscreen pillar, and down the wiring loom until it reaches this lowest point.
A squirt of WD40 into the connector, and some cleaning up of the contacts restored my speedometer back to full operational status. I was very glad I found the real issue before I spent considerable money on a new VSS!!