Sadly music theory is a huge subject, and I am doing my best to cut it in to pieces and offer it up to you guys in hopefully manageable chunks. There is some truth in both sides of your observation - there is a rule I am not mentioning, and you are expected to take what I say without question ;)
Seriously, the reason that in the key of G major you have an F# and not a G flat is that no letters are ever repeated, so you'd have G A B C D E F# G not G A B C D E Gb G. The only exception to this rule would be in a blues scale for instance where with the flat fifth added you end up with 3 notes in the scale a semitone apart and some repetition cannot be avoided.
So that's the simple answer - each note/letter only appears once in a key or scale. When writing music this also helps avoid having to write masses of incidentals.
I hope that helps, but please PM me back if I'm not being clear.
Check out my music, video, lessons & backing tracks here![br]https://www.renhimself.com