In hard water, calcium and magnesium ions react with soap molecules to form an insoluble precipitate called scum, which reduces the soap’s effectiveness.