I had the same question when I studied COD and COI, so maybe I can help!
The key point is to know whether there is a direct object (COD en français) after the verb or an indirect object (COI en français)after the verb. If there is COD, use le/la/les; if COI, use lui/leur.
For the example you provided:
Elle lui parle (She speaks to him/her)
we say "parler à qqn", so there is a preposition placed before qqn and after the verb, which makes "qqn" an indirect object. Thus, we use "lui" to indicate the person to whom she speaks. Here, it doesn't matter whether that person is a boy or a girl (masculine or feminine), we always use "lui" for the singular cases, and "leur" for the pluriel cases.
Elle le regarde (She watches it/him)
Here, we say "regarder qqn/qqch", so there is no preposition between the verb and its object, thus "qqn" is a direct object (COD), and we use le/la/les depending on what we want to express. Here, since you want to say "She watches it/him", we use "le" to replace "it/him" (must notice that "le" refers to a boy or a masculine thing and "la" refers to a girl or a feminine thing, don't mixed up!). "Je le regarde" is not the same as "je la regarde".
I hope my explanation is clear enough to understand! Message me if you have any questions regarding COI and COD!