The first thing to do is to approach this situation coolly and remain calm. Under no circumstances should you go along with those trying to blackmail you.
There is a concept of "cyberbullying" - minors are lured to take naked pictures and then are blackmailed with them. If you find yourself in such a situation, it is urgent to report it to adults you trust (it's great if you have a psychologist among them).
Don't blame yourself, and don't think you're the only one who could be in this situation. Many people worldwide go through the same thing, both their peers and adults. The main thing is to ask for help in time and not to be provoked, not to fulfill the blackmailers' conditions.