CursorLocker cannot be turned off

Hi, I’m trying to create a script that locks the cursor when it is active. It looks like this:

void Start()
{
    //This makes the cursor visible as soon as this script is active.
    Cursor.visible = false;
    Cursor.lockState = CursorLockMode.Confined;
}

// Update is called once per frame
void Update()
{

    
    if (Input.GetKey(KeyCode.Escape))
        Screen.lockCursor = false;
    else
        Screen.lockCursor = true;
}

And my other script, that turns this script off when a specific NPC is interacted with (So you can click the responses) looks like this:

// Update is called once per frame
void Update()
{
    //When we press E
    if (Input.GetKeyDown("e"))
    {
        //if we have inRange to true and inChat to false
        //(!bool1 is read as, "if bool1 is false")
        if (inRange && !inChat)
        {
            cursorLocker.enabled = false;
            //Turn on the window and load our initial text.
            npcWindow.gameObject.SetActive(true);
            chatText.GetComponent<Text>().text = greeting;
            loadDialogue1();

            //We don't want our lad to move, or look,
            //and we want his cursor back.
            playerMovement.enabled = false;
            cameraFollower.enabled = false;
        }

}

I have tested this with just the Movement script and the Camera script and it works fine. I’m pretty sure I referenced them correctly, but for some reason the CursorLocker still forces the mouse in the middle and hides it. When I play, and activate my NPC Script, the CursorLocker is visibly off in the Inspector, but its effects seem to remain. I am also sure there is only one instance of it in my scene. Is the way the cursor script is written keeping it active even when another script calls for its deactivation? Thank you very much for taking the time to read this…I’m working on a project for school and I’m unfortunately the only one in my group that knows some C#. Thank you again!

I would change your code to lock the cursor in OnEnable and free it in OnDisable. This way whenever the script is enabled and disabled, it will lock and unlock the cursor, respectively. Disabled scripts are not updated, so there’s no way to unlock it via Update once it’s been disabled.