The first thing I would like to stress is that you are not alone in this. Sure, it does not change your situation itself, but the realization this is not a problem I struggle with all alone lifted some weight off of my shoulders. I've heard so many stories of other people on the spectrum, asserting that they have no friends basically.
However, I also know it is possible to overcome this issue, even though I am not confident I know how to exactly. As Vanilla mentioned, knowing the cause of the situation is a good way to start.
Personally, I seem cold to others. I have a serious case of RBF, and my shyness is therefore often misunderstood as arrogance. When people talk to me nevertheless, oftentimes they are reassured I am arrogant because I usually reply like a robot, apparently. These are things that I find hard to change, so I try to balance them out by being a helpful and humorous person. It takes a lot of time for people to get over the cognitive dissonance I cause them but it works most of the time.
I am by no means a popular person, but the reason for that is my strict withdrawal from social settings because they drain me rather than my lack of social skills at this point. I am lucky to have found accepting friends that still enjoy talking to me even though I'm a hermit, or are on the spectrum themselves and don't care.
Long story short, I guess my best advice is to look for people who share similar character traits (they're rare so it's easier said than done, I know) and to find something you're good at or that makes you likable and sell it (like I started doing with my spontaneous humor). Also, be aware that your being a helpful person is a virtue, but limitless helpfulness will sooner or later be exploited, so it is necessary to fine-tune the dose.