So the shooter had mental illness for 12 years. He was on numerous medications and was being seen by professionals. In addition to this the police had made 26 visits because of his behaviour. Even with all this he was legally allowed to purchase a firearm in the last month or so.
Forgive me but it appears your laws and gun regulation really fucking suck based on the above. Additionally in this case fewer guns was the answer ... very clearly.
This isn't a failure of the background check system. The standard background checks would flag this if they were allowed to. This isn't a case of "gun nuts wanting more guns", this is a case of "snowflakes wanting to protect everyone". Medical issues are not allowed to appear on background checks by law. The idea was to protect people from hostile employers, i.e "Walmart doesn't need to know that I was hospitalized for PTSD when I was 18". Unfortunately this also shields seriously ill people from any scrutiny. Combine that with our love of handing out mood suppressing drugs to any kid that sneezes, and we have a recipe for disaster. I work for a public school, I have seen first hand what these kids look like once they start "treatment". If you put the lot of them on the set of The Walking Dead, i'd have a hard time telling the difference between them and the zombies.