Who told you off? what was their motivation?
A lot of people are all too ready to tell you what you should do, very often while not doing it themselves <dryly>
But to answer your question, I think @Mysticguru has it. Stay detached. Be kind, but only when it doesn't cost you more than you can afford with strangers/acquaintances/even friends, unless they are very close friends.
it's circles, isn't it? Like with grief. You are central to your own life; then come your children and your partner, your parents, your very closest friends. You share and give to them (specialy children) willingly, as long as you're not pouring everything out - you can't give from a position of emptiness.
Then less close friends, you'll help, but more when you can than really going out of your way.
The fact is that by the time you're 35+ you learn to keep half an eye on whether there's reciprocity in your giving with friends / partners, because there really are some people who will smile and give you a good time, but will also take and take and take while smiling, and leave you empty and then move on. Learning to take care of your self and your own resources is sensible, not mean.
Like I say, I'd be looking long and hard at who is telling me off, and why. It's a very strange thing to do to another adult.