I guess you mean improvisation. I think there are two Things to it. First one is practice. You Just have to do it and do it a Lot to get good at it.
Second is actively listening to the music you Like and maybe learning your Favorite Riffs, Solos etc and Paying Attention to what makes them great to you. So you can Incorporate These techniques Into your improv.