Battery in top condition is a must. I was saved enormous effort on my X when I read on one of these threads that 90% of electrical gremlins can be traced back to faulty ignition switch.
The solder joints are prone to failure. They allow intermittent operation for awhile causing (me) great puzzlement.
I bypassed the key switch entirely with a rocker switch and all of my previous symptoms have disappeared.
Hope this helps. An inspection of the switch mechanism is worth doing IMO.