Beginner that is confused about taking the queen

if moving the piece you wish to “capture the queen with” exposes your king in a check then it is illegal to move and on online chess that “illegality” is “unable to move”
it really helps if you have a game like this to post the game so we can tell you exactly what happened. I mean, there are only a few options here, sure -- either moving to take put you in check, or it wasn't a legal move, or you were already in check (not mate), or the more rare double check (have to deal with both, usually means king must move) -- but we can't say 100% without the board in question.
Hello! So I just started playing chess online, not as good as I thought I was. Anyway I have lost quite a few games by the opponent queen. Did I miss something in the rules? One game my opponent moved their queen to e5 and my Castle was on e4 and the game wouldn't allow me to take the queen with my Castle... Another game the queen moved to h2 and I had my pawn on g1, and the game wouldn't allow me to take the queen?! ( Both times I was not in check mate) it loses me the game Everytime
This had happened 4-5 times. Why am I not allowed to take my opponents queen?! I'm so confused