I believe we spend too much time trainging the fingers at the expense of training the ear. The mechanics are important but so is being able to hear what is being played. As musicians we have to be able to identify the interval being played ie: third, minor third, fourth , fifth etc. For most of us this is not intuative, it must be learned. Melody lines are some combination of intervals that follow a chord progression. If we can identify what we hear then we use our fretboard knowledge to play it. I know not as easy as it sounds but ear training is the key. We can then incorporate our melody line with improvasation and hopefully it's music.