Ive been playing guitar for 3 years, and I cant really say Ive written much. Ive made some stuff here and there, and what I have made that I like, I dont know how I could ever do it again, or Ill make something I really like, but its incomplete, and I cant figure out what to do with it. Ive started taking lessons for the first time, and when I ask him about songwriting, he just says, play what sounds right. Now, I know that thats probably true, but that helps me in no way whatsoever. Can anyone give me a nudge in the right direction? When people go to write, can they write just anytime anywhere? Or does something good just come to them out of nowhere? Do people USE theory to write? Or is it a guideline? Could I get some tips? I used to know alot of theory, but never knew what use it was, so I forgot all of it other than the 2 blues scale shapes and 2 major scale shapes.

Sorry for the wall of text XD
Being deeply loved by someone gives you strength, while loving someone deeply gives you courage.
i dont use theory a whole lot when writing. i know your basic scales, and if i cant find a decent chord to come next i'll figure out all the normal chords for whatever key i'm in, but that's about it.
my writing normally comes from just goofing around in a scale or with some chords, if i come across something i like, i'll stick with it and try to expand on it. normally if i sit down with the intention of writing, i cant write as well. i just wait for inspiration to find me. although, the more i write the easier it is to do it on the spot.
i cant say much for adding lyrics. i've never been good at that part.

if you know any scales, just mess around in them until you find a phrase or two that really sticks out and add on from there. or start with 2 chords in a key and see if you can take it anywhere. sometimes you can just jam on 2 chords all day and it's awesome, but normally it'll take adding on and filling out. takes practice and a whole lot of bad writing before you really get anywhere.
So, are you just talking riffs, or songs with Verses and Choruses that you just can't finish? In the case of the latter, maybe you should find somebody to write with like a friend. Maybe they'll hear where things need to go. A drummer can help with that by laying down the beat and making changes that will inspire you to take the songs in other places.
Try not to think of theory, use your creative mind and ear. I've written some of my favorite stuff after long periods of time without a guitar or even music. Theory does help, but forgetting about all your set chords and shapes helps you come up with good stuff often times.

If it comes into your head, keep it there and put it onto the guitar/paper. There is no set way to write, it is different for everyone.
when i write guitar parts i usually just play around on my guitar and find stuff that sounds good to me and that i like to play. and parts arent just going to come one after another. it takes time. Sometimes you can write a whole song in ten minutes, sometimes it takes months.