Time for some ear workouts!
Scale degrees
Don't know how to use this thing? Cool. Our goal here is to get a feel for how notes relate to a key.
This cool guy explains the exercise way better than I could:
Now, do this a million times and you should have a better time with improvising/transcribing/composing, and perhaps be a better musician in general.