Hard water contains calcium and magnesium ions which forms insoluble precipitate with soap which are sticky in nature
2C17H35COONaSoap+CaCl2→+2NaCl+(C17H35COO)2CaIsoluable percipitate
Soap forms insoluble precipitates with calcium and magnesium ions present in hard water.