Delete Unused Views, Schedules and Legends

I’m reaching out to discuss an error I’ve been encountering in my script. While the script runs successfully on certain occasions, more often than not, I’m faced with an error message. Any and all ideas would be greatly apricated.

image