It’s usually a bad contact in the switch or a connector. It could be due to oxidation of the contacts or physical deformation including being worn out. If the switch can be disassembled, oxidation can be cured with contact cleaners such as DeoxIt. But simply replacing the whole assembly will be far easier. Those switches are usually molded and cannot be disassembled.