I mean, I’m still not especially good at this, largely because I don’t do it very much at all, haha… but I think the answer here is thinking about how those scales/chords fit together and looking for ways to resolve from one tonality to the other; thinking about the differences between scale/arpeggio A and scale/arpeggio B, rather than just what those tonalities are.
For general improvization (rather than improvising extremely fast lines, which gets a little more regimented in what is and is not possible for you personally to play efficiently) really all you’re doing is making up melodies on the spot. The idea of just listening and trying to sing or hum (even just mentally) a melody line and then just playing that is a good one here, as others have suggested.
And the other good suggestion here is it’s VERY easy, especially for more technical playing, to let your fingers take the lead. You sometimes have to, for fast lines, but think about speed as a texture and it’s kind of how you come into and out of the faster stuff that matters…
…and then i’s just songwriting in general - tension and release, across as many axes as you can think of (fast/slow, resolved/unresolved notes, bent vs fretted, high vs low notes, whatever), and just trying to think about “constructing” a solo with a sense of development as it goes along.
I’ve gotten into the habit of practiing improvising jamming along to YouTube backing tracks… and honestly increasingly I’m thinking this is bad practice. Jamming along on a 7 minute backing track in your bedroom, you’re just sort of tossing out ideas, seeing what works, what doesn’t, workshopping technique, seeing what can flow at speed and what won’t… and you’re not really working on your improvisation beyond simply playing something made up on the spot. It’s a very different process than coming up with an improvised solo over a tight 45 second lead break in a song - the former is very free flow and kind of abstract, the latter is much more thoughtful since you have a clear starting point and ending point, so you tend to be a bit more disciplined about how you get from one to the other.
…which I guess points to another thing - sometimes giving yourself limits can really foster creativity. If you want a fun improvisational challenge, give yourself arbitrary constraints - “for this solo, I will only play on the B and D strings, nothing else” or “for this solo, I’ll alternate between two bars where I play NO chord tones, and two bars where I resolve every line on a chord tone.” That kind of stuff.