Barter is just too hard.
I need some groceries, yet I get paid in wheelbarrows from my factory job. Sure, the people at the grocery store might take my wheelbarrows for a while, but sooner or later, the farmers who grow the food that the grocery store sells will have enough wheelbarrows. Then what will I do for food?
Money works because we all agree to accept it, and it can be used in selling or buying anything else.
Precious metals could work as money, or something everyone uses like gasoline or toilet paper or whatever. But on a large scale, barter is just too difficult. You need something that all or most will accept as some form of money.