Melatonin is to reset the body’s natural circadian rhythm. You take it about 30 mins before you go to bed and then STAY OFF TECHNOLOGY and go to sleep in a darkened room.
It works by aiding your body’s natural sleep rhythm.
If you’re staying up late, start taking it 30 mins before you would normally go to sleep. After a few days, move it back by 30 minutes etc etc until you are sleeping in a natural rhythm of night time sleeping and waking up when it is light.