2000 Ford F150 5.4l Triton fuel pump issues?

I own a 2000 Ford F150 with the 5.4l Triton engine. Its the Ext. Cab FX4 package. For the past couple of weeks now when i go to crank my truck up, when i turn the key to the on position sometimes the fuel pump kicks in "you can hear the buzzing" but other times it doesn't turn on at all and it doesn't matter if the engine is cold, warm, or anything. So when you hear the buzzing from the pump the truck starts perfectly and idles properly and doesn't have any problems while driving. Then if i turn it off and come back to it, the pump might not buzz and the truck will turn over but almost instantly die but will usually shake the truck before dying as if its trying to stay running. Now this could happen in vise versa where it won't start cold and will warm. Also if i turn the key and it doesn't buzz i can usually turn the key back off and keep turning it a few times with a few breaks in between before the pump kicks in. I've checked the fuses and the relays everything looks good and no popped/burnt fuses in the cab box or in the box under the hood. I have no idea if the pump is bad, which doesn't seem like it since it sometimes works, or if there might be a loose connection or a short somewhere. Any info would help out a lot

Check the ground wire between the pump and frame/body. It may be corroded or loose.

Ok I checked the ground and it looks to be good. I undid it sanded it and the contact point but it seemed to be good