Once you have some of your basic scales down, you might try a little trick that I use all the time if you have recording equipment handy.
First, play your backup chords on an open track.
Then, with a microphone, go back through your chords while singing melodies and things on a second track that really make you feel like they belong. Go crazy, sing things that don't even belong and experiment.
With today's recording software you can easily do multiple takes or even splice together several parts into one 'great' take. So once you've spent some time singing and coming up with something you like, you can now go back and learn your own melody on the guitar using your knowledge of scales and chords to help you more easily work your way around the fretboard to play exactly what you heard in your head.
Scales and theory all all great starting points, but at some point you need to realize that there's an emotional element in writing songs that requires you to step out of the 'technical' aspect of your playing.
By just singing to begin with, rather than playing, your mind will be free of the technical clutter and you can really get into the melody and emotions that you want to convey in your song without worrying about where to place your fingers.