Can you link me to where that custom script was created?
This is not how a custom code shall be created and we do not, by support policy, provide custom code.
Note that the code repeats the lines over and over. This is not how PHP should be coded.
And, as stated before, we cannot assist the Custom Code. We can only guide you through the Toolset API.
That code does not use any Toolset API and is not related to Toolset Forms.
It gets eventual Fields, from the database, not from any Form, and does a SQL Query in the middle of the ShortCode, to get the Guids, and then returns that in a ShortCode "get_image_ids"
We cannot support this as it is simply not related to Toolset at all.
I see you use Toolset fields, but the entire logic and output of that Code is not based on Toolset - you can do the exact same with any other Field (not from Toolset) and still would run into the exact same issues, as our Image field is just a native WordPress Custom Field.
I am also not sure what you try to achieve, as Galleries are not created by Toolset like that.
Instead, you could use a repeating Image field and use that in a Form to add many images.
Then with the Repeating Fields Image Gallery feature that Toolset offers, you can create galleries with them
The code you have now cannot be stopped or broken by Toolset, as it does not use its API and the value of the fields is basically just an URL to the Image, so if that stayed the same, the code would still (independent from Toolset) work
But as said, I am not sure what it does, as it is not using any Toolset Feature or API.
If you create custom galleries with this I recommend consulting a contractor for the custom code part.
https://toolset.com/contractors/
If instead you have issues with the Form, which should upload an image or many, and it does not work, I can take a look but would need to have either the steps to replicate or a copy of the site (https://toolset.com/faq/provide-supporters-copy-site/) where that happens, as I cannot replicate such issue locally.
Thanks!