If you have this attached to an empty in the first scene you had this script active and it worked, you will need it to have an empty in the next scene with the same script attached as well.
Scripts don’t carry over to different scenes automatically, your code is fine, so that’s the only thing I can think of.