The most likely problem would be that your transfer case is shifting into neutral instead of 4 hi or 4 lo. This could be caused by a bad position sensor, bad wiring, a bad controller, or mechanical damage in the transfer case.
I don't know what transfer case your truck has, or any details, but I would start by taking the shift motor off the transfer case and see if you can manually shift it into all 4 positions: 2 Hi, 4 Hi, Neutral and 4 Lo, and double check that it operates correctly in all 4 positions. If not, your transfer case is damaged. If it does work, then you need to start diagnosing the electrical shift system parts, which will probably require a wiring diagram and an electrical test meter.