In the case of gasses there is a formula known as the gas equasion.
PV=nRT
Pressure times Volume equals the number of particles times the Gas Constant times temperature in Kelvin.
Essential for a given pressure and temperature there is always the same number of molecules present is a specific volume of gas regardless of the type of molecule.
Hence the density of a gas is always proportional to the molecular weight.