InsertNameHere More specific info might be helpful as far as diagnosing the issue - when you say "sometimes they don't work" do you mean the videos don't launch at all, or do you mean that they pay but stutter or crash? Which specific file types are you able to play versus not able to play? Etc.
But just about 75% of the time the solution is to follow CrystalRime's suggestion on installing the k-lite codec pack, as well as installing the HEVC Video Extension from the Microsoft store.
These two things should allow you to play h265 (aka HEVC) files, which I'm guessing are the ones you currently can't play.
I would suggest trying the above and if it doesn't solve your issue, more info & specifics would help us to troubleshoot.