That the person you're about to attack may have a gun on them will deter the majority of attackers. If nobody had guns, only melee weapons, it would be easy for a group to attack someone, say with baseball bats, etc., suffer little to no injury themselves, and get away. If everyone has a gun, you can ambush someone on the street, but will likely get killed by bystander. If you target someone in a location where they see/hear you coming, like their home or workplace, the attackers will suffer more harm than the "victim". This is more effective deterrent and solution to attacks than the police, who can almost always arrive only after the crime is over.
In countries with gun rights, like the US, the chance of someone not involved in crime being killed in a shooting is very low, and the number of victims in suicidal mass shootings can be minimized if even more bystanders have guns. It is unfortunate that it is impossible to quantify the number of attacks/muggings that never happened because the possibility of people being armed stopped them. This number is almost certainly huge.
Moreover, one otherwise cannot guarantee that the government will never ever turn tyrannical. An armed populace almost certainly can.

Articles by others on the same topic (1)