Learn which notes go best with which other notes. The best way is to understand and learn scales. They are the starting point of most tunes. Not just played as notes up and down as in actual scales, but to be able to mix and match.
A safe place to start is pentatonic. With five notes, and the other two iffy ones removed, just about everything played will start to sound reasonable. Get used to the major and minor pents.
Bear in mind that the two factors in improv. are the right notes and the right timing. But there is also a third: dynamics. Playing all notes at the same volume gets very boring very quickly. Imagine someone talking. Interest is kept partly by dynamics.
Talking about talking - a lot of music can be explained in conversation form. Question and answer if you like. A way in to this would be to actually have a conversation with someone, and, keeping the sentences each of you use short, straight after each, play what was said on your guitar. The rhythm is already there, just provide some notes! It's not easy initially, but anything worth while is like that.
Be very aware of what key you're in, and what chords and harmony are likely to occur in that key. For example, in key C, playing the notes D E F in a bar will fit far better over a Dm or G7 chord than over C or Am. But only by experimenting will you make sense of this side of improve. It can be done theoretically, but is much more effectively done practically. And, yes, there will be times when you can fit D E F over a C chord. I say to students: for now, only those 5 pent notes will work, but eventually, any note, any time, anywhere - you'll play and it'll sound good.
Work through different scales, modes, and eventually you'll arrive at the ultimate - all 12 notes of the chromatic scale, which can all be used in any key - once you know how!