They should live for a few years. A full grown molly is about 4 inches, and ones sold in chain pet stores are never that large. Often only 2" at most (males are thinner, but about the same length).
Unless you bought one that was 4" long or so, the fish was less than a year old.
Mollies are extremely hardy fish, and can weather all sorts of water conditions that would kill other fish.
So the fact your fish died so so means you either bought one that was ill, but not so ill it was obvious. A healthy molly is a hyperactive little fish that never sits still. In chain stores (all we have here) that sell them, I have yet to see a healthy molly for sale. They are all listless even shimmying. Some even have clamped fins. None of these things are good signs, and a fish with any of these symptoms is not doing well.
If the fish was lively when you first bought it then, perhaps your water conditions are poor. If that is the case then they'd have to have been out of whack for a while to take down a healthy molly.
Mollies bought in pet stores are NOT tropical fish. They are hybrid of a Sailfin Molly species common throughout the Southern US where temps. regularly get down to freezing in winter, and they do fine. They are sometimes crossed with Common Mollies which also live in the Southern US, but their range extends into the tropics. Regardless, that means temp. is not a big concern, unless you experienced wide, rapid swings, which I seriously doubt.
One thing that can make a healthy molly sick very quickly is a lot of stress. Being high strung, once put in the tank at home they should be left alone as much as possible so they can calm down.
I have lots of mollies, and I am talking from experience as well as research in regard to where the mollies in the stores came from.