When things are not going your way, you can do 2 things( I am going to say the obvious but I’ll say it anyway)- 1. You can give up and hope for life to give you a lucky moment/opportunity 2. You can (continue to)work hard till you earn that opportunity.
It’s very rare for an opportunity to fall in your lap without you working for it. Even if it does, consider it a one-off case. Instead, when things aren’t going your way, go back to working hard and being sincere. Go back to giving it your best and being disciplined. Go back to knowing and believing that hard work is always followed by a pay. With that, your motivation is constant and so are the opportunities. All you have to do is work and not give up.