Ok, so if you're looking to take a song on guitar and work out the key the easiest way is to look at the chords being played, and work out the key they all relate to.
If the song goes like this:
C, F, G, C
We can see the that these are the I, IV and V chords of C Major
I, IV, V, I
Or a different example:
Dm, G7, C
Is also C Major, with ii, V, I being the chords.
For a major key the chords will always be (from I to VII):
Major, Minor, Minor, Major, Major (Dominant 7), Minor, Minor b5, (Major at the root again)
If the song is a natural minor then this pattern still works, but it starts at the 6th, so in a minor the chords will be:
Minor, Minor b5, Major, Minor, Minor, Major, Major, (Minor at root again)
Be aware there may be key changes, and there are loads of potential scales to base their key off. These are the one I encounter the most.
So the basic idea is the take your list of chords, and figure out how they all fit into one of the above patterns. Once you get that you can read off what scale you are in.
There are all kind of reasons why using the melody itself may not be the best approach. Often it makes songs interesting to use modes and other tricks to play notes that shouldn't strictly fit. I'm not going to go into that now as that may be unecessary. As a bassist it's far more useful to have the chords, work out the key (or keys if it changes) and then go from there. Of course, some chords will fit into multiple keys.
This sort of practise is incredibly useful when improvising or writing your own material. Being able to take a set of chords and work out the key is something that is essential. By the sounds of it, looking at some interval ear training may be useful too - being able to tell the sound of a major 3rd or minor 3rd is useful.
Eventually, by listening to alot of songs it will get easier. What song was it you had in mind? If it is well known there will be tabs of it on the internet, so for the first few use those to help you. There's a few good books on guitar music theory too by Hal Leonard I would recommend if you want to get into this sort of thing.
Disclaimer - as music is very subjective there are almost always exceptions to rules. If you're looking at jazz or something similar then some crazy stuff will happen.