Hard water is caused by salts -- you're perfectly right to think that.
The key thing though is that there are many kinds of salts. We everyday folks usually think of "salt" as just one thing -- table salt or the salt dissolved in sea water. This particular salt, sodium chloride (NaCl), is just one of many salts in our universe.
To a chemist, a "salt" by strict definition is what you get when an acid and a base are able to chemically react with each other. The offspring of that get-together is a salt.
Soap is a salt -- a sodium soap is a salt of any fatty acid (there are many) and sodium hydroxide (a base). Table salt is the reaction of hydrochloric acid (HCl) and sodium hydroxide (NaOH). Hard water ions -- the calcium (Ca) and magnesium (Mg) ions I talked about earlier -- come from naturally occurring salts in the earth. Some salts dissolve easily in water, some don't, so it can be a trial-and-error learning process to know what any particular salt will do in a given situation.
A sodium or potassium soap is fairly soluble in plain water, but a calcium or magnesium soap is completely insoluble. A calcium or magnesium soap acts just like a blob of grease in a pan of plain water. In fact certain types of these insoluble soaps are actually used as lubricants.
Hard water + soap does this:
Sodium soap (soluble in water) + Calcium (Ca) ion => Calcium soap (insoluble) + Sodium (Na) ion
Sodium soap (soluble in water) + Magnesium (Mg) ion => Magnesium soap (insoluble) + Na ion
When a sodium soap is used in salty water, the problem is less a chemical reaction and more of a physical change. The sodium ions in the water prevent the soap molecules from dissolving in the water. The longer the soap molecules are (soap made with lard, tallow, palm, or liquid oils), the less likely they will dissolve off the soap bar. The littler the soap molecules, the more likely they are to dissolve.
Think of the sodium ions in the salty water as big, burly guards trying to prevent criminals from escaping their bar-soap prison. The little criminals are faster and more agile. They are able to sneak past the guards much easier than the bigger, slower moving guys. :shifty:
I hope this helps!