Gateway Tag Change Script or Local Tag Change Script

Oh, yes. Your script is very much unsuitable for definition on the tag itself. Some reading and further links: