Hi Anonymousgirl291, welcome to the group
What you went through sounds really painful -- first a breakup, then a betrayal, especially while it seemed like your friend was helping you.
You're not alone in going through a situation like that. Back when my H and his kids' mom (with many BPD type traits) were together, my H's former best friend was "helping" them with their relationship issues... but before the divorce was final, the "best friend" was dating H's ex. It's clear to me now that H's former best friend has many NPD type traits.
When there's a PD (or more) in the mix, healthy boundaries are often absent. Healthy boundaries would be things like "I don't use someone else's distress as a way to get in a relationship with them", or "I am honest with others about the relationships I'm in". pwPDs (people with personality disorders) tend to have poor boundaries, and also may use people and relationships as ways to get their deep needs for "feeling OK" met. A person with BPD may seek to attach to someone else in a desperate attempt to avoid feeling abandoned. A person with NPD may view "getting the other guy's girl" as a statement of his superiority.
PD's are by definition disorders, so when we try to "make sense" of the choices pwPDs make, we often hit a wall -- that's the disorder. It won't make sense to a "broadly normal" person why sudden breakups, betrayals, role switching, etc, are "okay" to do, yet for a pwPD, those choices meet their extreme emotional needs.
How do you think you'll navigate those relationships, going forward? As you're posting on "Detaching", I'm guessing you are done with both of the relationships?
Let us know how you're doing, whenever works for you;
kells76