The weight-loss process for those who've been overweight for a long time involves changes to lifestyle and mental outlook. The processes which got the person into an unhealthy body have to be identified and completely replaced.
It's like quitting smoking. You can go "cold turkey", but that works for few people. It's more often the case that people will quit, FAIL, quit again, FAIL, quit again - and stay smoke free until a major personal upheaval which they use as an excuse to start smoking again, FAIL, then, finally, quit for good.
Once a weight-loser begins to see a healthy lifestyle as NORMAL, and practices that habit, then the old unhealthy habits will fade into the past like bad memories. But it's like learning to ride a bike - there'll be falls, but eventually it becomes second nature.
There are a couple of mental tricks I've developed for myself which you might find worthy of consideration.
1) Just "doing things" to lose weight didn't work in the long term. Try this: "Be different" and then the "do different" comes out as a natural expression of internal change - instead of treating change like a foreign thing grafted on (as as we know, a body can reject grafts).
2) Setbacks are not the end, they are just a few steps that make up the thousands of steps needed to reach a goal. One step backward plus two steps forward equals one step forward.
3) Recognise that the weight-loss process will provide more than just weight-loss. A person learns about nutrition, discipline, confidence, their inner self. They can improve their self-motivation and social life, their outward and inward appearance. I can think of lots more, but will end here.
Keep going J, don't give up.