When Ronald D. Moore was on the writing team for “Star Trek: The Next Generation,” he rarely appeared on set for the episodes he wrote. But he made a special exception for the show’s sixth season finale, “Descent,” an episode that kicked off with the only guest appearance in “Star Trek” history from a celebrity playing himself: the late physicist Stephen Hawking.

“Only the people involved in filming the scene were actually allowed in the room,” Moore recalled in an interview with TheWrap. “Everyone else was crammed out in the hallway peeking in. It was a really exciting scene and one that had never been done before on ‘Star Trek.'”

Historical figures are no stranger to “Star Trek,” whether it’s simulations on the Enterprise’s holodeck or the time Kirk and Spock teamed up with Abe Lincoln in a fight to the death. But to this day, Hawking is the first and only person to play himself in the over 50-year history of the sci-fi series.

Also Read: 'Star Trek: Discovery' Just Confirmed Klingons Have Two of Everything, and We Mean Everything

Hawking’s entrance into the annals of Starfleet began in 1991 when he visited the Paramount Pictures backlot, where he was set to introduce a documentary made by Errol Morris about his life. While there, “Star Trek” producer Rick Berman discovered that Hawking was an avid Trekkie and offered to give him a tour of the “TNG” set.

“After that visit, we learned that Hawking would be interested in doing a cameo on the show, and there was a window of time when he was going to be back in Los Angeles and I was going to write the episode they were going to film during that window” said Moore.

“So I got the call and they told me, ‘We need you to write a scene with Stephen Hawking,’ and I’m like, ‘Wait, WHAT?!’ But they told me to do something on the holodeck, maybe with Data.”

Surprised that he was going to be writing lines for one of the most famous scientists of the 20th century, Moore decided a scene as a holodeck simulation programmed by the android Data (played by Brent Spiner) would allow Hawking to play a game of poker with Albert Einstein and Isaac Newton.

The scene opens with Hawking — using his actual computerized voice — making a joke about the “perihelion of Mercury.” Moore wanted to make a physics joke, but had no idea what it would sound like. So he called in his college roommate, co-writer and future “CSI” showrunner Naren Shankar to provide his expertise.

“Naren had a Ph.D. in applied physics, so I brought him in, and he was also tickled at the idea of writing lines for Stephen Hawking. So he was the one who came up with the idea of the joke being that Stephen keeps busting the chops of the other scientists and that Isaac Newton is a jerk and that Einstein and Stephen keep bagging on him. Once we had that, the scene just wrote itself.”

Moore remembers how excited everyone on the set was when Hawking came in to do the scene, including Spiner, who Moore says was usually able to easily sink into Data’s calm, emotionally still state of mind, but was extremely nervous about sitting at a poker table across from the man who discovered black hole radiation.

Also Read: 'Star Trek: Discovery' Star Jason Isaacs on the Toughest Thing About the Shoot

“We were all just so amazed because here is this guy who totally expanded what we know about space and it turned out that he was a ‘Star Trek’ fan. It felt so amazing to have that connection as people who have created stories in this universe.”

In the following years, Hawking appearanced on other TV shows, including “The Simpsons” and “The Big Bang Theory.” But as fans of science fiction commemorate his life alongside those who studied science facts, Hawking’s deepest connection to pop culture is still with “Star Trek,” a show that premiered seven months after he submitted his Ph.D. thesis on the origin and expanding nature of the universe.

“In some ways, we’re playing in a sandlot that he helped build,” Moore said. “It spoke to the power of imagination that a man who spent so much of his life literally inside his own head and thought about the great questions of existence still wanted to be entertained and have his imagination stimulated.”

“Every week we were taking ideas that he postulated and twisted them around and played with them. I liked the fact that a man like him wasn’t disdainful of what we were doing, that he could appreciate science fiction.”