because your using $nick in the ON NICK event, "On nick" = On nick change which you can trigger this persons old nick with $nick but for any variables or whatever or mode changes you must use $newnick as I noticed you got a if ($nick isop #chat) change to if ($newnick isop #chat) :P