It's probably the vehicle speed sensor. It's located on top of the rear differential.
When the sensor isn't working right the speedometer doesn't work and the computer doesn't know how fast the truck is going, either. It needs to know this to know when and how to shift the transmission.
A new sensor is well under $20. I recommend changing it. It's an easy 5 minute job. There is one electrical connector and one bolt.
This forum is owned and operated by Internet Brands, Inc., a Delaware corporation. It is not authorized or endorsed by the Ford Motor Company and is not affiliated with the Ford Motor Company or its related companies in any way. FordŽ is a registered trademark of the Ford Motor Company.