Generally you want to post your code using the # button and select 'code' so the code is easier to see instead of getting mashed to the left in a proportional font. You can use 'preview post' to make sure you get it looking reasonably well.

Also, you were vague as to what 'sometimes' means. You didn't say how this was called, such as 100% guarantee that it's only called from within an event where $nick is defined, and not in a timer or a right-click menu.

Bugs are easier to nail down if you include some echo commands to the status window which include $scriptline $nopath($script) and contain variables etc, so you can triangulate the error. For example, an echo at the top of the alias can verify whether $nick is actually defined, and whether %nop2 is set correctly too.

Also, if you put an echo right above your 'return' commands, so you can identify which of the 2 returns might be the one that has the error, or whether they both can generate the error.