Issue with script adding IP to add-list from MAC-addr

Hi all,
I made a script that has a list of MAC-addresses and then it will find the associated IP and put that into an address-list.

When I was trying the intermediate pieces, the script was working and the list was created.
However after I have added a simple filter to avoid adding over and over the same IPs if they are already within the list, the script does not run anymore.
I don’t see errors in the log, therefore I’m posting it here in case someone has any idea what is failing.
I’m running the latest RouterOS 6.46.6.

Thanks and regards,
Armando.

:global stopScript false;

:do {
	:local MACaddr {"A4:43:AC:C4:91:8A"; "00:12:13:41:57:6A"};
	:local inAddrList 0;

	:foreach i1 in=$MACaddr do={	
		:local IP_Addr ([:pick [/ip dhcp-server lease print as-value where mac-address=$i1] 0]->"address");

		:if ([/ip firewall address-list find list=LB_Disabled address=$IP_Addr]) do={
			:set inAddrList 1;
		}
		:if ($inAddrList = 0) do={
			/ip firewall address-list add list=LB_Disabled address=$IP_Addr
		}
		:set inAddrList 0;
	}
	:delay 60;
} while=(!$stopScript)

Just a quick question.
Is the goal to av access list for certain mac address and then to do some with it?

If this is IP from a DHCP, why not make those IP static?
I convert all my DHCP to static IP to make sure all clients gets same IP all the time.

Yes, you’re absolutely right about doing it easier with fixed IP.
Basically I did it like that, at the beginning. I made these 2 devices to be outside DHCP and assigned them their IP and manually added them to the list.
However for other reasons I wanted to keep them again on DHCP, so I tried initially to use firewall-raw rules in pre-routing with src-mac-address to build the list, which worked fine too.
But then I didn’t want to engage raw-prerouting that much and also I didn’t like that added addresses are dynamic and lost after reboot, so I decided to do it over scripting.

At the end the issue was most likely that when the list contains IPs the script was not running and exited from the loop.
So now I have changed the scheme and it’s working fine.

:global stopScript false;

:do {
	:local macAddrList {"C8:69:CD:D7:91:9B";"00:16:6B:51:67:7A"};

	:if ([:len [/ip firewall address-list find list=LB_Disabled]] > 0) do={
		:foreach i1 in [/ip firewall address-list find list=LB_Disabled] do={
			/ip firewall address-list remove $i1
		}
	}

	:foreach i2 in=$macAddrList do={	
		/ip firewall address-list add list=LB_Disabled address=([:pick [/ip dhcp-server lease print as-value where mac-address=$i2] 0]->"address")
	}	
	:delay 1800;
} while=(!$stopScript)

Again, as you indicated, not the smartest way (better to use static LAN IP), but till when I’m keeping them into DHCP, this method will do the job.
Armando.