UPDATE: Just updating this in case anyone faces the same problem in the future.

It seems like my issue wasn't with the script but with the...