I received an email the other week from someone who had written a screenplay based on a popular video game and was wondering how to market it. The answer was...you can't. Not without the permission of the people who own the game. I've come across other situationst in which authors based screenplays or novels on material for which they don't have the copyright.
It's never a good idea!
In some cases they were hoping that the copyright owners would be so impressed by their version that they'd be happy to buy it or let them try to sell it elsewhere. If this has ever happened, it's a very big exception. Most of the time--I'd say 99.9% of the time--you will have wasted your effort and be left with something you can't try to sell.
The exception is material in the pubic domain. That's why there was no problem writing "Pride and Prejudice With Zombies," for instance.
Another thing to be careful about is a situation in which someone comes to you with an idea or maybe a book they've written and asks you to write a script on spec (no money now) and promises you a nice fee if and when it sells. If it's somebody who has great connections, it might be worth it. Otherwise, though, if they can't sell it, you end up with a script for which you have limited rights. You won't be able to sell it yourself without their full cooperation. I've gotten into those kinds of situations in the past and at least in my experience it's not a great idea.
Bottom line: stick to your own ideas. That way the rights and the control remain in you own hands.
(If you would like to write but aren't sure how to go about it, I suggest my book, "Your Writing Coach," which takes you from the idea all the way through to publication or production. It's published by Nicholas Brealey and available from Amazon and other online and offline retailers.)