A lot of really kind, giving, lovely people worry about being selfish. They are concerned that doing something for themselves or putting themselves first for even a moment is being selfish… it isn't. That's not what being selfish means.
You see a similar thing with people who have low self-esteem, they worry about being overconfident or that others will think they are arrogant when, in truth, they are not. If you are the kind of person who worries about being arrogant, then there is a very high probability that you are not. Similarly, the same applies here, if you worry a lot about being selfish, then you are almost guaranteed not to be.
One of my biggest pet peeves is when a person is trying to encourage a friend to treat themselves and they use a phrase like, “Go on, be selfish” or “Be a bit selfish” because it is the biggest turn off and makes the person less likely to do it. It's not a helpful phrase and as general rule, saying, “Be [negative thing]” is rarely going to be useful, so please try to avoid using it in a pep talk.
You are allowed to care about other people AND about yourself. You almost need to put yourself first for the most part and make sure that you are okay because if you're not okay, you're not going to be as much help to other people. If you put yourself at the top, you can still have everyone else in a very close second place. There is a world of difference between “doing something for yourself” and being “selfish”. Doing something for yourself ISN'T selfish.
Seriously, look at dictionary definitions for “selfish” and you'll see that they talk about acting “without regard for others” or “without consideration of others”. So as long as you are thinking about others when making your choices, being considerate of their feelings, then you're not being selfish. Similarly you'll see definitions talk of acting “only” or “excessively” in one's own interest. So long as you are frequently there for your friends and supporting others, then you're not just doing fine, you're doing more than fine.
Be good to yourself. Be kind to yourself. You're not being selfish.