Writing numbers for the purpose of record keeping began long before the writing of language. See History of writing ancient numbers for how the writing of numbers began.
It is generally agreed that true writing of language (not only numbers) was invented independently in at least two places: Mesopotamia (specifically, ancient Sumer) around 3200 BC and Mesoamerica around 600 BC. Several Mesoamerican scripts are known, the oldest being from the Olmec or Zapotec of Mexico.
It is debated whether writing systems were developed completely independently in Egypt around 3200 BC and in China around 1200 BC, or whether the appearance of writing in either or both places was due to cultural diffusion (i.e. the concept of representing language using writing, if not the specifics of how such a system worked, was brought by traders from an already-literate civilization).
Chinese characters are probably an independent invention, because there is no evidence of contact between China and the literate civilizations of the Near East, and because of the distinct differences between the Mesopotamian and Chinese approaches to logography and phonetic representation. Egyptian script is dissimilar from Mesopotamian cuneiform, but similarities in concepts and in earliest attestation suggest that the idea of writing may have come to Egypt from Mesopotamia. In 1999, Archaeology Magazine reported that the earliest Egyptian glyphs date back to 3400 BC, which „…challenge the commonly held belief that early logographs, pictographic symbols representing a specific place, object, or quantity, first evolved into more complex phonetic symbols in Mesopotamia.”
Similar debate surrounds the Indus script of the Bronze Age Indus Valley civilization in Ancient India (3200 BC). In addition, the script is still undeciphered and there is debate over whether the script is true writing at all, or instead some kind of proto-writing or non-linguistic sign system.
An additional possibility is the undeciphered Rongorongo script of Easter Island. It is debated whether this is true writing, and if it is, whether it is another case of cultural diffusion of writing. The oldest example is from 1851, 139 years after their first contact with Europeans. One explanation is that the script was inspired by Spain’s written annexation proclamation in 1770.
Various other known cases of cultural diffusion of writing exist, where the general concept of writing was transmitted from one culture to another but the specifics of the system were independently developed. Recent examples are the Cherokee syllabary, invented by Sequoyah, and the Pahawh Hmong system for writing the Hmong language.