In addition to establishing setting, character, and plot, it is important, when writing a story, to establish morality. That is, to make sure the audience will consider your protagonists to be on the right side and your antagonists on the wrong. It needs to feel that the protagonists deserve to win.
Obviously, this is not the case in every story: you can have one where both sides are wrong, or the protagonist is a villain, or so on. Only, if you do that, you still need a reason why people should care what happens.
For a simple example of this being done well, I offer the episode Rooting for the Enemy from Milo Murphy’s Law. The idea of this one is that Milo – a middle-school boy cursed with absurdly bad luck – decides to help out his school football team by rooting for the other team, ensuring that his bad luck rubs off on them. It’s a funny premise, but the problem is that this does look a little like cheating. By imposing his abysmal luck on the opposing team, isn’t Milo unfairly influencing what is after all just a game?
The show sidesteps this in a clever and amusing way: they establish that the opposing school is already cheating, since they’ve been purposefully failing all their best football players for years until their team is basically made up of “a group of angry adults.” Not only is that cheating, but it’s a lot meaner than anything Milo does, putting his team in an impossible and rather dangerous position. So, when Milo plays unfair, he does so to redress a much worse unfairness that the other team has done.
This device also serves to one, give Milo a reason to be at the game in the first place (the team specifically asks him to stay away, as his bad luck inevitably spoils their chances, but since they’re obviously going to lose they give him permission to come this time) and two, put his team into a position that would require Milo’s intervention to extract them.
Now let’s look at an example of this done badly: the episode The Mysterious Mare-Do Well from My Little Pony (yes, My Little Pony has its share of bad episodes). The premise is that Rainbow Dash, after receiving praise for saving ponies in need, becomes even more self-absorbed than usual, to the point of being arrogant and careless. Her friends then show her up by creating a masked hero who is better than her at everything, forcing her to confront her bad behavior.
The major problems here are one, that the other ponies never tried simply talking to Rainbow Dash about her behavior, and two, that Rainbow didn’t do anything wrong. The worst you could say is that she was getting careless and rude, but she was still helping people. Also, Rainbow becomes seriously depressed and upset over the situation (she has a history of emotional fragility), but still the others don’t simply tell her what’s going on and even rub it in her face at one point, which is frankly a lot meaner than anything Rainbow does (all the more so because, when they do tell her what’s happening at the end, it takes her all of two seconds to agree with them, meaning the whole rigmarole was unnecessary). It’s jarringly out of character for them to behave this way, and frankly our sympathies are entirely with Rainbow Dash. The episode failed to justify the actions of the ‘good’ characters relative to the actions of the ‘bad’ character.
The Milo episode works because the writers recognized the potential moral pitfall and carefully turned what could have been a liability into an asset, making the story stronger and raising the stakes. The plot device of the other team cheating by keeping their players into adulthood both provides the conflict and justifies Milo’s actions. One side is cheating in a way that could cause real harm, so Milo rectifies it by arguably cheating to help his friends.
The MLP episode doesn’t work because the writers failed to establish the conflict to the point that it would justify the heroines’ actions. This could have easily been solved by simply having a scene of Twilight confronting Rainbow Dash and having her blow her off and by having another scene where Rainbow Dash’s self-aggrandizement actually caused real problems, rather than just being annoying. Those two scenes would have pretty much salvaged the episode by putting the morality of the story on firmer grounds.
The point is that basic moral rules are as important in creating a good story as anything else. If the characters’ actions don’t fit the reaction we’re meant to have to them, the story won’t work.