It's not outputting anything because you don't fetch the results.
What you want to do is COUNT all DISTINCT records, example (untested):
PHP Code:
$resCNT = $vbulletin->db->query_first_slave("SELECT COUNT(DISTINCT userID) AS online FROM " . TABLE_PREFIX . "ajax_chat_online");
$num_chatting = $resCNT['online'];
vB_Template::preRegister('navbar',array('num_chatting' => $num_chatting));
vB_Template::preRegister('FORUMHOME',array('num_chatting' => $num_chatting));