In that case, your original script is almost right:
on *:text:!connect:#:{
/join $chr(35) $+ $nick
}
The reason your original script didn't work is because # is evaluated to the current channel, just like $chan. So you need to use $chr(35) or $(#,0) or $eval(#,0), whichever you prefer