The ON QUIT event does not have a channel attached to it, so if you are in more than 1 channel, you must first verify if the person was in the channel being monitored.

Code
ON *:QUIT: { 
  if (!$nick(#channelname,$nick)) return

  same code as in the JOIN event goes here

}