I think the issue might be considered under different aspects: one behavioral and one physiological.
Girls (and others in general, for that matter) don't like guys with problems, needy, unhappy, unfulfilled, depressed, without a scope/enthusiasm in life, without interests and passion, etc...
Read the above again several times: it is a really important point.
If not having a girlfriend or/and friends makes you feel like the above of course things can only be spiraling down, the more you get depressed and needy the more girls an others will keep a distance from you and you wil get even more depressed and needy and it never ends...
My suggestion is first stop feel bad because you don't have satisfying relationships, it plays against you, it doesn't help at all to change things and anyway.... always consider that is much better alone than in bad relationships!
Find yourself something interesting to do that fulfills you, something to be passionate for, something that makes you feel alive and kicking.
It may be sport, it may be culture, it may be traveling, whatever it is doesn't matter, your happiness and satisfaction is the only thing that really matters.
Don't do it for others, don't try to please others, do it for yourself, as selfish as it comes.
You don't know where to start?
Well, try something new, maybe something you always thought about just like a fantasy... life is now and procrastination may lead to missed opportunities.
Once you'll be happier with yourself others will be attracted to you because it is nice to be around an happy person, as simple as that.
But don't just act as happy, it doesn't work, you have to really be happy for it to work.
Stop thinking you need others in order to be happy, it is the other way around: you need to be happy in order to have others!
Leave them alone, don't reach for them (or you'll get hurt, as you already experienced), let them come to you and if they don't doesn't matter: forcing things will only worsen things guarantee.
In the path to make yourself happy and fulfilled some physiological factors may be involved too, but don't make the mistake to take that as an excuse to ignore the above!
I don't know how old are you but anyway it may happen at all ages...hormonal unbalance, especially low testosterone but not only, leads to depression and more.
Consider an hormonal test.
If you don't train I warmly suggest you to do so, weight lifting does good for hormones and not only, of course.
Don't under valuate hormones and/or other physiological factors in how deeply they can influence the psyche and behavior, often is just that and you can turn the situation around almost overnight, but not with recreational drugs for sure.
Recreational drugs are not going to improve things, actually will very likely make them even worse, I am not against recreational drugs (not to some of them, at least) but those are not meant as a substitute for happiness, use in that way leads just to more troubles, usually big ones.
If you want things to change you have to change how you do things.
Since worrying is not going to change anything to worry is totally useless, be happy instead since it is by far more constructive (and fun).
And by the way you aren't the only one experiencing what you do, it is much more common than you think.