Caffeine is a stimulant, and melatonin is a not-a-stimulant that makes you sleepy. So if you take them both at the same time, you're basically canceling each one out. The caffeine will make it harder for you to sleep, and the melatonin won't be able to do its job.