If you are talking about bayonet style (use #44 bulbs as an example):
You need one of these:
https://www.marcospecialties.com/pinball-parts/77-SCS
It shines up the bottom contact in the socket.
It also cleans just the area where a bulb would rub on the sides of the socket.
After using this to clean the bottom contact, take needle nose pliers and slightly bend the 'tabs' at the top of the socket in a bit.
Now when you put your bulb in the socket it should be quite hard to insert, and the metal tabs should tightly grip the metal sides.
If you are talking about the wedge base style (use #555 bulbs or #96 flashers as an example):
Make sure the metal finger contacts in the socket aren't bent to one side or the other. Sometimes I use a 'spring hook' tool to pull the contacts out a bit and bend them so that they will grip on the bulb wires better.
If the connection is poor on a wedge style bulb or LED, I take the wires at the bottom of the bulb, and move them to their other sides. This makes connection with a different piece of metal inside the socket. It also makes sure that the wire at the bottom of the bulb is correctly aligned to make connection with the bulb socket fingers.
For older pinballs, like 80's solid state and various gottliebs, the sockets fail. They fail a lot.
Replace them. You can do some hacks, but the better answer is to replace a lot of sockets.