I can answer that because I am in no way any musician - just a technician with some gear and lots of source.
for the most part you have to be born that way and have the music in your head that needs to get out ... but with technology and persistence, you can fatten those melodies up and then refine it.
either way, it takes dedication and time, a lot of it. with today's "stems" technology, (dance/club) music is delivered as a package but able to be split into components (percussion, bass, synth, vocals) ... have a search for such technology to see how you can build on a simple melody.
I'm not suggesting that you buy the technology, although I do use it at home, but it might give you ideas.