![Mg^(2+)](https://img.qammunity.org/2020/formulas/chemistry/high-school/sgm0nhf4ptv11fwgudik0ble7v5m8p47oq.png)
Atoms want to be stable, that's essentially their only purpose in life.
How, then, does an atom become stable? Well, they either lose all their electrons, or gain electrons so they have 8 (Except for a couple atoms like helium, they just need two electrons).
Magnesium has two valence electrons, and obviously it seems a bit unconventional to try and gain 6 electrons when you could just lose 2. Why spend more effort?
Because it loses 2 electrons, Mg will become
(It has lost 2 electrons, and therefore becomes positive)
Good luck! If you have any questions, just ask :))
-T.B.