The creation of a song is not always the duty of the guitarist. Sometimes the guitar player might write a chord progression (Am, C, Em, F for example), and its the vocalist's job to try to sing a melody over that, and you're on the way to a song. More often than not, a song will only remain in one key. Modulations (change of key) may take place, but its not easy to do it decently.
As for solos, there're many solo techniques. You don't spam scales per se, because if you are in the key of Cmaj, the only scale you're gonna be spamming is the Cmaj scale, and that's only one scale. Not to mention it will sound terribly boring. Usually people improvise, or come up with something different, of course reflecting the motif of the song.
Some ways to do this:
1. Re-arrange the melody
2. Repeat the melody in a different octave and adding some new turnarounds etc.
3. Alter the groove of the song
The list is endless, its up to you to explore the options available.
If you want to get technical about constructing a melody over a chord progression, the easiest way is to utilise chord tones - the notes which the chord progression contains.
Hope this helps!