Hmmm. I used to write scripts like those, but I discovered that if an error sometimes happens during betting (like if your internet connection is too slow), you would lose all your progress (since the script only keeps it in memory, and that's lost when betting stops). That's why there's more manual work in using my scripts now, because I've heard a lot of people complain before that their autobet would stop randomly, which would make an all-or-nothing script dangerous to use.
But basically...the way I would do it, is create a table in code to store numbers that are hit. Then, every time you hit a number in current code, rather than stopping, do the following steps:
Check if the rolled number exists as a key in the "hit numbers" table
If it doesn't, then add a new entry to the table, with your rolled number as the key and the bet ID as the value
Loop through all the numbers we're trying to hunt, and see if they all exist as keys in the table
If they do, loop through all the numbers in the "hit numbers" table, print out the value (the bet ID), then stop betting
If not, continue betting as normal
If it does, continue betting as normal