I'm fairly new to learning music theory at a basic level. I understand notes, triads, intervals and how to read sheet music but I am struggling to understand key scales and how and when they apply and how to use them correctly to create melodies. I understand chords and how key scales affect the tone/emotion of the chords and overall track. I've written a melody that I like which is: A# F# F D# C# D# F# F G#
I believe it is a A sharp minor scale. Would I need to change the natural F as it isn't in that scale in order for it to work, is that what you would call out of key? Can you play one note out of the scale if it sounds better to you or fits better with what you are writing, would that be out of key or is there a name for this? Do you need to apply the same scale to every instrument you're working with?
Is my thought process and understanding correct? If not, please could someone explain?