#1
Hey, so every now and then a riff or melody that i really like pops into my head. i can hear it perfectly in my head, and it sounds awesome, but when i pick up my guitar and try to figure out how to go about trying to play it, i just dont know what to do or where to start.

Any tips?
#2
ear training try playing song by ear start with simple melodies christmas carols and the like and you favortie songs
also learn to at least hum along to your guitar so when you think of a riff you hum the melody or whatever and can try to figure it out like that

a bit of music theory never hurts with this since it can help you to figure out how the riff you wrote works musically

good luck with this
#3
^ what that guy said, really learn your intervals also (5ths, 4ths, 3rds etc) and by learn I mean learn what they sound like all over the guitar
#4
Try the book "Ear Training for the Contemporary Musician" by Keith Wyatt et al.

That's a vital skill if you want to write music. Most people aren't born with it, and it takes work and time to improve.