That question has at least four answers because writing was independently invented at least four times in human history: in ancient Mesopotamia, Egypt, China and Mesoamerica. The scripts of these civilizations are considered pristine, or developed from scratch by societies with no exposure to other literate cultures. All other writing systems are thought to be modeled after these four, or at least after the idea of them.
With future research, the number of pristine scripts could decrease, if archaeologists find evidence that any of these cultures copied the idea of writing from one another (most likely Mesopotamia and Egypt, because geography). And the number could grow, if other ancient symbol systems are deciphered and proven to represent true writing. But as it stands, most scholars believe that just these four scripts had independent origins.
A remarkable peak into the origins of a distinctly human activity. I wonder what internet forums would look like without the written word?