Also, why did the League of Nations fail to prevent World War 2, while the UN never had to deal with a World War 3?
Let me first deal with how the League (L of N) failed to prevent WW2. Generally the L of N was ineffective in opposing German aggression, which led to the start of WW2. Firstly, the League relied on a system of unanimity, which meant that all member nations had to agree for any action to be taken. This then meant that if any nations disagreed with the action, no action could be taken. Thus, the League was largely ineffective in dealing with any political conflicts because some member opposed the actions taken. For example, the League did not take any action in the Japanese invasion of Manchuria, or France and Belgium's invasion of the Ruhr.
Secondly, the League had no real resources or power to take any action. The League had no army to act, and had to rely on member nations to take action themselves. Furthermore, major powers such as America and Russia were not members. The League thus had little power to act and prevent political and military conflicts. This led to the League's inability to enforce disarmament and discourage Germany's militarisation. Germany was able to start rearmament from around 1935-1936, growing its army, navy, and establishing an air force extremely rapidly. The League proved itself to be unable to respond to any aggressive powers, which defeated its aims of collective security in the first place. This eventually emboldened Germany to invade Poland in 1939, beginning WW2.
From this we can then see how the United Nations tried to solve some of the problems of the League of Nations. The United Nations (specifically the UNSC) firstly does not operate on a system of unanimity, although permanent members do still hold veto power. Secondly, the UN has a small peacekeeping force from member nations, which it does use occasionally to prevent political and military conflict. Lastly, almost all major powers such as Russia, USA, etc. are a part of the UN, giving it legitimacy and power. While the UN does have issues and problems today, and is not completely effective, the UN has tried to resolve some of the problems of the L of N, which hopefully serves to prevent future conflicts and possibly World War 3.