Why do I keep doing this?

I keep saying I will lose weight I will lose wdight I will lose weight and I end up losing 2 pounds and gain it back and quit. How do i actually lose the weight and not eat bad food and starve? I did that 2 years ago and lost 36 pounds. I’m obese and I’m 17 and school is starting In 2 months. I’m ugly and fat.