The 41-year-old "Happy" hitmaker addressed New York students on March 20, reported Ace Showbiz.
"I'm staring at the future right now. Hello to the future," he said.
After greeting the young attendees, the Grammy winner stated, "Music brought me happiness. And when you find out what makes you happy - and it can be something as detailed as a long-term goal or it can be something as simple as the way I feel when my son smiles - you should know that happiness is your birthright.
A special "Happy" playlist featuring a selection of songs picked by numerous stars like Britney Spears and John Legend was played during the event.
Williams was joined by environmental activist Philippe Cousteau and oceanographer Sylvia Earle at the UN event. After his speech, the singer was mobbed by the students who were holding up their cellphones and cameras ready for selfies. The three speakers also managed to take a selfie together.