Here's how Optimus leaves Earth and the end of the film goes in Brian and the Eeveelution Family's Adventures of Transformers: Age of Extinction.
[Optimus lands on a helicopter platform]
[Cade and Tesa embrace]
Cade: Kind of nice being your hero for a change.
Tesa: You always were. All my life.
Cade: I love you.
Tesa: I love you, too.
Cade: Let's go home to graduation, huh?
Cade: [to Shane] You're okay, kid. Come here, you're all right, all right.
[They all hugged, then Joyce walks up]
Tessa: We don't have a home, dad. It blew up.
Joyce: I might be able to help you with that.
[Cade and Joyce hugged]
[Bumblebee drives up]
Optimus: Brave warriors.... you are free!
[The Dinobots transform]
Cross-Hairs: I'll ride with you anytime, Spike!
Grimlock: ROAR!!!!! [he takes off with the other Dinobots]
Duck: [giggles] I like those robot Dinosaurs!
[Su Yueming runs up]
Joyce: Did you miss me?
Su Yueming: No.
Optimus: This Seed belongs to our creators, whoever they are. There remains a price on my head. I endanger you all if I stay. [he wields the Seed] I shall take it where it could never be found.
Cade: Will we ever see you again?
Optimus: Cade Yeager, I do not know. But whenever you look to the stars, think one of them. As my soul. Defends this family, Autobots, as they have you. Defend. All they can be.
Brian: Optimus, we're gonna miss you.
Optimus: And I will miss you too, Brian. But you must keep me close. And you will always remember me. [takes off]
Brian: Then may the Force be with you.
Optimus: [takes off, then sends out a message] There are mysterious to the universe we were never meant to solve. But who we are and why we are here. Are not among them. Those answers we carry inside. I am Optimus Prime and this message is to my creators: "Leave planet Earth alone. Cause I'm coming for you."
[The movie ends with "One More Light" playing in the background. And in the last shot, it shows a picture of Chester Bennington, saying: In Loving Memory of Chester Benninton. March 20, 1976 - July 20, 2017. And it fades out to black]