XS3 contains one cation of X and three S2− ions.
Valency of one S2− = 2
Valency of three S2− = 2 x 3 = 6
The compound XS3 is overall neutral in charge. So, the valencies of the ions must be balanced while writing the chemical formula.
Therefore, the valency of 'X' is 6.