Joystick freezes when entering a different scene. Please help me fix this!

I added this script to the canvas on which the mobile stick was.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class JoyStickController : MonoBehaviour {

    private static bool joystickExists;

    // Use this for initialization
    void Start () {
        if (!joystickExists)
        {
            joystickExists = true;
            DontDestroyOnLoad(transform.gameObject);
        }
        else {
            Destroy(gameObject);
        }
    }
   
    // Update is called once per frame
    void Update () {
       
    }
}

But for some reason when I go to the other scene the joystick freezes.
Here is a video of demonstrating it:

I’m not sure if putting on the canvas object like you are doing is causing your problem.