Not Starting When the engine is cold on 2000 Ford Ranger

Rookie cbe0621eac06868b3efe0d8d1d3611e23c60d3114864ea2ec19a68cfbd3eebab
In the mornings or at night, usually when the truck hasn't been driven in a while and the engine is cold I have problems starting it, i'v noticed if i put my foot on the accelerator while i start the truck it helps sometimes. Sometimes when i'm driving the power cuts, for example if im listening to music , i'll notice the music stops and the RPM's drop and after a few seconds it goes back to normal. I'v taken this to my mechanic and we changed the o2 sensor and it helped for a bit but the problem is still occuring and he doesn't know what it is. Sometimes it helps if you tap the ABS box under the hood. does anybody know what's wrong?
(1) Answer
Start by making sure the battery cables are clean and tight, because corrosion will cause power loss from time to time even though everything looks clean