Check for codes and then check the MLPS (Manual lever position sensor) connector for corrosion/wetness. There was an issue on our trucks with this. There was a technical service bulletin in like 95 or so. If you look on the driver's side of the transmission it's the black plastic assembly that the shift linkage connects to. If that doesn't fix it (cleaning or replacement) check the VSS. My vote is MLPS though.
VSS= Vehicle Speed Sensor (it's on the top of the rear axle.)