You either make rules for mentally unstable people getting guns, give kids free mental healthcare, or put a gun in every classroom.
That last option is an insult, btw. Yes, sell more guns. The progressive, high-road solution. I guess if you locked it in an extremely secure vault that can only be opened remotely, but that would be a total copout to solving the problem. The solution is to have the kid maybe only kill a couple of other kids, then for a teacher to shoot the shooter dead, maybe cutting the amount of deaths in half.
Our school had a free therapist, that's a good start. But not everyone benefits from that, some people need free meds too. And free stays at psych wards.