If you want some tips, I usually just bang around on my piano or my music software until I get something that sounds nice or interesting, and then I build off of that strand of notes until I get something out of it. Then that phrase can turn into being either a melody, harmony, or sometimes even a counter melody or harmony in the finished song.
There's a lot of trial and error, and you have to train yourself to know which notes played together will give a certain feel or sound. I've scrapped many songs because I didn't like how they were turning out, but then I may reuse bits of them in other songs. Or I might write two completely separate phrases, but then realize that they sound good when played together.
It's also okay to "borrow" small phrases from other music, so long as it's not a direct copy or rip-off of that song, and you have plenty of original music coating it.
Like stormylullaby said, it just takes practice.