Hard contains calcium and magnesium ions. When soaps are dissolved in hard water, these ions displace sodium or potassium from their salts and form insoluble calcium or magnesium salts of fatty acids. These insoluble salts separate as scum. This is the reason why donot work in hard water.