in the beggining stark was about to get loki's stick but the female twin did something and stark was in a state of delusion or something and was seeing a nuclear wasteland with his teammates dead/dying and the aliens from the first movie winning.
what was all that about?
Most Helpful Guy
Later in the movies, Nick Fury confronts him about the vision. Tony's worst fear isn't dying. It's being the only Avenger to live, knowing he was responsible for it. The whole reason he was sleep-deprived in Iron Man 3 is because he saw the Chitauri ship, and all the other ships behind it. He was convinced that Thanos was just going to bring more and more Chitauri, and that stopping Loki wasn't enough.
Seeing the other Avengers all dead in the vision convinced him that they needed someone who could replace them in their jobs. Someone who would be disposable should the Chitauri invade again, thus giving the Avengers a safety net so they aren't always the first line of defense - which he believes is doomed to fail.
Due to glitches, Ultron awakes to see only the worst in humanity. And from there, he feeds on Tony's fears and sense of hopelessness to develop his own twisted, perversion-of-Genesis-6-themed, worldview about being Noah and staring the world over.
Either way, Tony is convinced that the apocalypse is coming, and that he'll somehow be responsible for it. For all his tech know-how, his core is a scared, bratty little child lashing out in desperation. This has always been his fatal flaw, and becomes the reason Ultron acts out like a rebellious teen. He inherited Tony's worst attributes.0