Have you made the mistake of mismatching pronouns? Almost everyone has. That includes the venerable and usually perfectly grammatical New York Times, most of your favorite writers--and me. I have a master's in English, I've studied linguistics, and I've been a professional author and journalist for decades. I've still messed this up in my own writing. If you want your own prose to be clear and also grammatical, you need to follow the rules governing pronouns and antecedents. That may sound obscure, but it comes up in pretty much everything you will ever read--or write.
As a refresher, pronouns are words such as he, she, I, you, we, they, me, her, him, us, it, and them, among others. I, me, you, and sometimes we are self-explanatory. Every other pronoun must refer to something mentioned elsewhere. That's where the trouble starts.
He/him, she/her, and it refer to a singular antecedent. They/them refers to a plural antecedent. That sounds simple, but it's not. Words like every, everyone, and each, among others, are singular and take a singular pronoun, even though they refer to multiple people, animals, or things. "Every house has its [not their] roof."
But when we refer to people (and sometimes animals), things get blurry, because English has traditionally lacked a gender-neutral singular pronoun. Most of us don't want to write sentences like "Every doctor has his favorite patients," or "Every nurse has her favorite patients," because of the clear bias implied. Not to mention that there are plenty of female doctors and male nurses. For years, grammarians recommended using he or she in these situations, or else recasting the sentence as a plural, for instance, "All doctors have their favorite patients."
Times have changed, though, because of the growing acceptance of they as a singular pronoun for a person whose gender is unknown. This was helped along by Demi Lovato and others who identify as non-binary and choose the pronoun they to describe themselves. These days, a sentence like "After the performance was over, everyone got in their car and went home" is considered grammatically correct by most experts--because they is now accepted as a singular pronoun.
Just in case that isn't complicated enough, there's another rule for inanimate objects. If something can be counted, it's considered plural (unless there's only one): "Some of the diamonds fell out of their settings." If it can't be counted, then it's singular as in "Some of the sand fell out of its pail."
Number agreement is confusing enough. But you also have to put the pronoun in the right spot in relation to whatever it's referring to. For example, most grammarians say the antecedent has to come before the pronoun, making a sentence like this one wrong: "When they saw the police surrounding them, Bonnie and Clyde knew their time was up."
Whether antecedent-before-pronoun is a strict grammar rule or not, it's a rule you should follow most of the time. If the above sentence were part of a longer paragraph about Bonnie Parker and Clyde Barrow, it would be fine because readers would know from the start who they referred to (and there would probably be an earlier antecedent). But a reader who encounters the sentence without that context--as you just did--would likely have a moment's confusion about who they are before the rest of the sentence clears it up. That sort of thing can break the flow for someone who is reading your writing.
And here's a rule that confuses even the best writers: The pronoun should refer to the last thing or person mentioned. Consider these sentences found by editor Bonnie Mills, writing for The Writer. "The room contained a chair, a desk and a lone light bulb. It was 26 feet long by 17 feet wide."
"That's a pretty big light bulb!" Mills quipped. Since it generally refers to the most recent antecedent, those measurements belong to the light bulb and not the room, grammatically speaking. This, too, is a rule you should follow because it will make your writing clearer. But if you've gotten it wrong, don't feel bad. Many good writers have too.