"Switch" your script to a particular connection (/scon and /scid commands) and execute commands on that connection, or use $scon() / $scid() identifiers and properties. Have a look at /help Multi-server

2 examples:
; if theres a Nth connection
if $scon(N) {
; switch to this connection (it's connection ID)
scid $v1
; now you can do whatever you like - all identifiers etc are evaluated for this connection id
echo -a Here on $network my nick is $me
; return to the current connection
scon -r
}
if ($scon(1)) {
echo -a Network 1 has connection ID $v1 . It's name is $scid($v1).network and my nick there is $scid($v1).me
}