In the UI, the script is reused from one run to the next. So you cannot use let nor const in the script’s outer context. For example:
let foo = 1; // error on second+ run
const bar = 2; // error on second+ run
if(foo) {
let baz = 3; // no problems
const biz = 4; // no problems
}
This is something unique to UI rule script actions and conditions and probably will be addressed at some point. In the mean time use var or wrap the whole thing in a self calling function.