Why does hard water not produce foam with soap easily?
Soaps contain Na & K salt of long chain fatty acids . When they are dissolved in hard water (which contains Ca & Mg ions) ,these ions replace the Na & K from their salt to form insoluble Ca & Mg salts of fatty acids these insoluble salts separate as scum.
2C17H35COONa + CaCl2 → 2NaCl + (C17H35COO)2Ca