Following these tips should help you stay on the right side of the law when making a fan game. Do not use the original game’s name or branding in your fan game. Do not sell your fan game, or charge for it in any way. Make sure your fan game does not include any copyrighted material from the original game, such as art, music, or code. This is usually the game developer or publisher.
However, there are some general tips you can follow to make sure your fan game is legal: -Get permission from the copyright holder of the original game before you start making your fan game. There is no one-size-fits-all answer to this question, as the legalities of making a fan game will vary depending on the country you are in, and the game you are making a fan game of.