This doesn't work.
if (% != $null) {
do this
}
else (% == $null) {
do this
}
/else doesn't take a condition, so it wouldn't work, would it?
Perhaps in future it would be better to post your scripting "bugs" in the Scripts & Popups forum, or spend 30 seconds in a help channel to see if anyone can explain them.