I'm not sure there's a way to
teach someone how to write melodies. It comes naturally to some people, and it definitely helps to have a background in music.
For me, it's harder to come up with a melody to go with my lyrics, than lyrics to go with my melody. It's even better to write both simultaneously.
How are you trying to come up with melodies? I think it helps to start with a few chords on the piano, or a riff on the bass, play it over and over again, and start humming a tune that goes with it. Then, you can try to incorporate the lyrics. Some words may be added or changed, to go with the rhythm.
This is what I do in my songwriting process. I hope it helps! Let me know if you have any more questions.