Melatonin can work, but it isn't a panacea.
Treatment by taking a pill or having a procedure done is called a passive therapy because it requires little effort on the part of the patient. People who rely on passive therapies (the surgery was supposed to "fix" my back, for example) usually do poorly. Only those who rely on passive and active therapies (meditation, bedtime habits, etc...) succeed.
That being said, there is scientific data showing that melatonin can help your body know it is time to sleep and help fall asleep. Other studies have shown no tolerance with continued use. While some studies show little evidence for melatonin, the supplement itself poses little risk. Unless you are pregnant or breastfeeding, the risk/benefit may warrant a short trial to see if it works for you.
When I was in pain medicine most treatments and procedures I performed, even putting in spinal cord stimulators, were to get people to be more active and perform physical therapy. In sleep, I would recommend that any pill, supplement, or product is not the end-all and should be used with other therapies. If you still struggle after a melatonin trial, consider that Cognitive Behavorial Therapy might work better. Exercise, diet, and solving your inner struggles may be the solution.
I used to tell patients that usually one therapy wouldn't kill their problem. Try getting 20% victories from 5 different buckets (diversifying your therapy). For example, people think that physicians hate alternative medicine (not true). It was another bucket I could draw from!
What I took to sleep while I worked in prison was a padding for a multitude of habits I had to get to sleep quick. I used meditation, relaxation, and mindfulness as well to get over the fact I could be called anytime.
In short--try many techniques for sleep, and heavily weight active ones. If melatonin doesn't work, great. You found something that you can scratch off the list and you are one step closer to finding something that does.