"It was a big surprise! We got so excited when we saw him," said senior Justice Tolbert.
Cosby shared his struggles and talked about the importance of education.
"Age 19 was the time I found myself at rock bottom. I had done a horrible job at planning my life," Cosby said.
When he entered Temple University, Cosby said he changed his life. Now, he's urging students to take school seriously.
"Guess what I didn't do that you do?" Cosby asked the crowd. "Study!"
Cosby's visit was a big hit, but it took some persistence to get him here. The principal, Dr. Parthenia Moore, said she spent a year trying to get Cosby after seeing him speak at Central High School.
Moore said she approached him to speak, wanting him to inspire her girls the way he inspired his own Alma Mater.
"I talked with him at that time and found out his mother was a graduate. He really wanted to come and make connections and be partners with us," said Moore.
She said kids sometimes need to hear this kind of message from someone who started exactly where they did, and prove success is in their control.
"It's hard to come out of Philly," said senior Siani Miller. "You can make it and be exactly like he is."