Hi @Denise_H and welcome!
I can’t see in this script what can cause the errors.
Please check the post below for an easier method to change your scene(s).