OK, maybe you can't write a novel or a screenplay in your sleep, but you can certainly generate useful material.
In my book, Your Creative Writing Masterclass, I mention several great authors, including Robert Louis Stevenson, who spun stories from their dreams. In her book, Writers Dreaming, 26 Writers Talk About Their Dreams and the Creative Process, Naomi Epel cites some others.
Amy Tan, author of The Joy Luck Club, said, ""Sometimes, if I'm stuck on the ending of a story, I'll just take the story with me to bed. I'll let it become part of a dream and see if something surfaces."
William Styron, author of Sophie's Choice, said he had a "lingering vision" of a young woman with a tattoo on one arm and he "was seized by this absolute sense of necessity--I had to write the book." He said the ""whole concept of the book was, if not the product of a dream itself, the product of some resonance that a dream had given me."
Writing mentor and novelist John Gardner has said that a work of fiction should read like "a vivid and continuous dream," so to some degree you can use your own dreams as a model for what you write. Naturally dreams are much more chaotic than novels or scripts, but they're raw material that you can shape, edit, and combine.
Dreams are especially useful for people who want to write children's books because their surreal elements can be adapted for picture books or fanciful fairy tales.
If you don't remember your dreams you can train yourself to do so. Every morning jot down anything at all you remember, even if it's just one tiny fragment. Over time you'll begin to remember more and more. You can dicate rather than write, if you prefer, using a digital recorder or your smart phone.
If you have writer's block, remind yourself before you go to sleep that you'd like to dream a solution to the problem that's blocking you and see what comes up.
Give it a try; if it works for you, you can have a good sleep and still say you were working all through the night.
(There are lots more great tips in "Your Creative Writing Masterclass," published by Nicholas Brealey and available from Amazon or your other favorite bookseller.)