Exes and complications.

I need advice. So my ex and I have had a very complicated relationship for the last two years since him and I broke up. Our reason for ending the relationship was because at the time my family didn't like him and told me to break up with him. Well I didn't. I lied to my family and said we did. He said that if I didn't send him nude photos of me that he wouldn't forgive me. I told him I don't do things like that and he ended things with me. It was wrong of me to lie I admit I should have defended him and of course I regret not doing that. After awhile of breaking up he contacted me again. He started calling me every day and the conversations would go on for hours. Eventually I was dumb enough to sleep with him and I regret it very much. I was very stupid and wish I could take it back. Honestly I thought by doing all that maybe he would forgive me. But he He didn't. He started being very mean to me. Calling me names. Would argue with me when I had a new boyfriend. He even told a guy I was dating at one time that I slept with another guy just to ruin our relationship.😢 I don't know what happened. I told my family the truth and apologized to him. Now he has a girlfriend and has thrown me out like garbage. In all honesty he doesn't last in a relationship because all he wants is sex and dirty pictures. I don't talk to him anymore because of all this but once in awhile he'll try coming back but only for sexual things. What should do?