although your question is probably way too ambiguous to answer, here's my best response. most modern (western) music relies on chord resolution. if your melodies are periodically moving around and back to one note, that note should be the "tonic", or the root of the key you're in. for example, in C major, the note C is the tonic.
essentially, most songs start and end on the so-called tonic, or root note. this applies to both melody and harmony (chords). i would recommend starting to look at chord progressions, especially the 2-5-1, and 4-5-1 to begin. if you know how to write melodies then it should make sense pretty easily. there are many more things to consider but this is a good start.