Traditionally in Europe: religion. As a more general answer than religion, which covers the other answers here: culture. Scripts comes from a particular culture, and adherents of that culture adopt that script. If speakers of the same language belong to different cultures, they use different scripts. If there is a massive cultural shift in the language community, then everyone shifts script.
The critical thing to note here: writing is a cultural artefact, much more thoroughly than language is. So it does not pattern with language, and can change even more quickly. It can change by fiat, or by proselytism, more quickly than language does.
So three hundred years ago, Greek Orthodox Christians wrote Greek in the Greek script; Greek Jews wrote Greek in Hebrew script; Greek Muslims wrote Greek in Arabic script; and Greek Catholics wrote Greek in Roman script. Four hundred years ago, Orthodox Cretan authors wrote Greek in Roman script too—because they were writing Renaissance plays influenced by Italian culture, and all their Ancient Greek references were via Italian. The Orthodox churchmen in Crete at the same time were writing in Greek script.
Ditto Albania, with the added mess that some Albanians made up their own scripts. Coming up with a single Albanian alphabet was a necessary step to having Albanian nationalism override the credal identities of Albanian subcommunities.
Hence what used to happen with Serbian, Croatian, and Bosnian. It flabbergasts me that Serbs also use the Roman alphabet, but that’s about a new culture (or religion): Westernism. Which is also why Turkey switched to Roman.
Hence also the merry-go-round of scripts in the former Soviet Union. Arabic (Islam); then Latin (Westernism); then Cyrillic (Sovietism); then Latin again (Pan-Turkism).
Chinese Traditional vs Simplified is partly about culture (rejection of the past), though of course many of the simplified characters are older cursive forms, so they’re hardly made up out of thin cloth. There was some Westernising enthusiasm around Pinyin, but certainly not enough to displace the ideographic script.