Question: how many valence electrons does mg2+ have?
Answer: if an atom of an element is electronically neutral then the number of protons (atomic number) will be equal to the number of electrons. Therefore Magnesium atom has 2 valence electrons, which explains why it likes to form Mg2+ cations by losing the latter 2 electrons.