The subscript 2 indicates number of Cl atoms
Further explanation
The molecular formula shows the number of atoms of a compound
whereas the empirical formula is the simplest comparison of the atoms making up the compound
MgCl₂ is an ionic compound composed of Mg and Cl atoms
Mg is in group 2 which has a +2 charge, while Cl is in the Halogen group which has a charge of -1
If the two are bonded, the 2 electrons released by Mg will be bound by 2 Cl atoms, each of which atoms of Cl need 1 more electron in order to obtain a stable electron configuration such as a noble gas
So the number 2 in the MgCl compound indicates the number of Cl atoms