Post History
Even if I'm not really a fan of the stories, I always take Fifty Shades of Grey and Twilight as best example for exactly this question. Fifty Shades of Grey was originally a Fanfiction of Twilight....
Answer
#3: Attribution notice added
Source: https://writers.stackexchange.com/a/48680 License name: CC BY-SA 4.0 License URL: https://creativecommons.org/licenses/by-sa/4.0/
#2: Initial revision
Even if I'm not really a fan of the stories, I always take Fifty Shades of Grey and Twilight as best example for exactly this question. Fifty Shades of Grey was originally a Fanfiction of Twilight. But in the end, it ended up, like it did now. Also, I'm helping a close friend to write his first book, that based of as a Final Fantasy Story of his own. The most important thing in cases like this are: Keep your text away from things, that belong to others. You can write in the same world of course, but the whole problem is: Everyone will know what is up, if you use special trademarks of the series. A reference to Harry Potter will be clear, if your guys will mention the dude with the lightning scar on the forehead. There it is crystal clear, that you are mentioning Harry Potter (because the lightning scar on the forehead is his trademark). If you left off the lightning shape, it would be totally different, but no one could be sure that you mean exactly him. The same with the spells. If you are writing about the Harry Potter world, there is the common thing, that the spells are the same, all over the world. So either you need to invent new spells to use for your characters, or you have to use the existing ones, what would lead to copyright issues. If you are planning to write something like that and plan to publish it for money: Don't ever mention anything from that universe. If you plan to write a FanFiction, you can use the whole work as your playground. But you can't sell it, cause it would lead to copyright issues.