Without looking at the script, tough to say…
If you post code, please use the ‘Insert Code’ button. Please and thank you!