Sure but criminals still consider the potential consequences every time they break the law and most criminals in Germany made the decision
that it's not worth breaking the law to own a gun because the risk is just too damn high and if caught you will end up in jail for several years.
Now we are talking a matter of degrees. Of course laws, consequences and punishment deters undesirable behavior. But not for everyone. Harden criminals are a very small proportion of the population but they make a disproportional impact.
You can completely ban gun ownership, like they do in Mexico. In fact, you can shut down all gun companies in the country. In "double" fact, you can ban all guns in the world. But it's still not going to stop the availability of guns.
There is something about this world that people are just not willing to accept. The "cosmic" battle between good and evil is never going to end. There will always be a perpetual state of conflict. There is no solution per se other than to allow the good guys to defend, protect and fight the bad guys. The way you stop a person with a gun is another person with a gun. It's already been shown that States that allow concealed carry have less gun crimes than States that don't. What house are you going to break into? A house that has a sign: "Ban Guns" or a house that has a sign: "Protected by Smith and Wesson". That why schools, a designated "gun free" zone is a better target than, say, a police station.