Check the GH, KH and pH of the water. Mollies need a GH above 250ppm to thrive and if it's too soft (not enough minerals) they start to shimmy, which is similar to what yours is doing.
If you don't have a GH/ KH test kit, contact your water supply company by phone or visit their website and find out what the GH (general hardness) and KH (carbonate hardness) are. If you can't get the information from them, take a glass of tap water to the local pet shop and ask them to test it for you. Write the results down in numbers when they do the test. Find out what the test is measured in (ppm, dGH, or something else) and write that down too.
In the meantime, do a big (75%) water change and gravel clean the substrate. And clean the filter if it hasn't been done in the last 2 weeks.
If there's no improvement after cleaning the tank, and your GH is suitable, add some salt.
---------------------
SALT
You can add rock salt (often sold as aquarium salt), swimming pool salt, or any non iodised salt (sodium chloride) to the aquarium at the dose rate of 1 heaped tablespoon per 20 litres of water. If there is no improvement after 48 hours you can double that dose rate so there is 2 heaped tablespoons of salt per 20 litres.
Keep the salt level like this for at least 2 weeks but no longer than 4 weeks otherwise kidney damage can occur. Kidney damage is more likely to occur in fish from soft water (tetras, Corydoras, angelfish, Bettas & gouramis, loaches) that are exposed to high levels of salt for an extended period of time, and is not an issue with livebearers, rainbowfish or other salt tolerant species.
The salt will not affect the beneficial filter bacteria, fish, plants, shrimp or snails.
After you use salt and the fish have recovered, you do a 10% water change each day for a week using only fresh water that has been dechlorinated. Then do a 20% water change each day for a week. Then you can do bigger water changes after that. This dilutes the salt out of the tank slowly so it doesn't harm the fish.
If you do water changes while using salt, you need to treat the new water with salt before adding it to the tank. This will keep the salt level stable in the tank and minimise stress on the fish.
When you first add salt, add the salt to a small bucket of tank water and dissolve the salt. Then slowly pour the salt water into the tank near the filter outlet. Add the salt over a couple of minutes.