Friendly reminder from Wugideon:

Thanos dies in the first five minutes, but has already destroyed the stones, so they go back in time and get the stones. Then, Scarlett Johansson dies, and Nebula from the past switches with the future one and brings Thanos back from the past through the time machine. Hulk uses the stones to bring back everyone, and Thanos fights them with his army. Thanos gets the stones, but Iron Man gets them back and kills Thanos with them, but dies in the process. Captain America goes back in time to return the stones, but stays in the past and now he's an old man