Personal experience: I have mild insomnia* and I sometimes take melatonin. It generally does help, but I can be groggy in the morning, if I took it too late in the evening. Happens sometimes. But for me, it's so much better to be sometimes a bit groggy for a short while, compared to being completely exhausted from sleep deprivation all day.
*I was a startup founder for 10 years and practically did not sleep during that time. Even years after that life, it feels like my body is not responding to melatonin that much. Or my body is not secreting enough itself. Who knows.