Gateway laptop shuts off when plugged in

Now I've been having this problem pretty recently and don't know whether to get a new charger, battery, or just buy a new laptop (which is the last resort). What keeps happening is when I have the charger to the laptop plugged in while running an application (mainly games) it the screen will cut to black and stop functioning. The lights still glow as if it is still on and the music from the game would still be playing, meaning it hasn't shut completely off. The only way to make it stop is to force shut it off, by holding the power button or taking out the battery. I mean the laptop is decently old, not too old, and doesn't have this problem when not plugged in. It has just been getting on my nerves recently and has even started happening more frequently.

If there is an fix that doesn't require the spending of money that would be appreciated, then I'll just have to wait. I just want to play LoL and these leaver busters are making making me unpleased.