I'm not sure why you're checking $nick !ison $chan.
Since the newnick is $newnick, then $nick can't be on the channel, I haven't tested but your condition is certainly true all the time, I would use :
on !*:NICK:{
if ($newnick ison #your_channel) && ($hget(table,$nick)) {
hadd table $newnick $v1
hdel table $nick
}
}
I've added the ! prefix, only trigger the event for other people than $me and check for $newnick ison #chan.
For the on quit event it's basically the same but since we know that the nick isn't there anymore, you have to check for $comchan on $nick :
on !*:quit:{
var %a = $comchan($nick,0)
while (%a) {
if ($comchan($nick,%a) == #your_channel) && ($hget(table,$nick)) {
hdel table $nick
break
}
dec %a
}
}