Freezing Value when not logged in

Hello,
i’m trying to script a connection supervision. There for the lasd Handshake Value from the wg peer is read. The script works when i’m logged in with Winbox, but when i disconnect, after a random time this value freeze.

:local lastHandshake [/interface wireguard peers get "0" last-handshake];
:log info "WG-1 Last $lastHandshake";

This line creates a local value with the time. “0” is the number of the interface, the quotas are for tests, don’t know maybe the number ist string or something else, but without quotas is the same problem. At the moment i just log the value for tests. The script is started by the scheduler every 2m5s. I can see it works when i’m logged in vie winbox, but when i disconnect, a random time later the value freeze (see in log when i connect after while in winbox). After login it works again. Any hints?

V7.7 on hAP ac2

As already written thousands of times, the numbers to identify the peer only work from the terminal, it is normal that they don’t work on scripts.
You must use the name of the peer, not the number obtained on the print (and not 0 just because it is the only peer)

Thank you very much. The peers in wireguard doesn’t seem to have a name, so i used the following line which works.

/interface/wireguard
:local peer [peers/find public-key~"o1Y2.*"];
:local lastHandshake [peers get $peer last-handshake];