There are many different reasons why people gain weight. A pill is not a cure-all, but it can help get started.
I read "Ultra-Processed People: The Science Behind Food That Isn't Food" recently. It certainly gives food for thought, about how and why some people eat more than others. In a nutshell, some food is not actually real food but "an industrially produced edible substance". These substances may have the same calories, proteins, carbohydrates and fats as real food, but because they're not real food, your body can be tricked into eating more. For example, try eating a real homemade loaf of bread versus a sliced loaf of bread, and see which takes longer to eat, which makes you more full and which you will eat more of.
So, if you're eating more because you're eating mostly industrially produced edible substances, aka junk food, then fixing your obesity by taking a pill is kind of disgusting. Chemicals to fix chemicals. A big problem, though, is that real food is a lot more expensive than junk food: industrialisation brings down costs.