Access function in another script cause Object reference error

I have a ScriptA in this Script I have a listener on a Button and I want that this listener invoke a function that access another function in the ScriptB

So I have tried this code in ScriptA :

confirmButton.onClick.AddListener(MyConfirmFunctiom);

function MyConfirmFunctiom(){
	var myScriptB:ScriptB=GetComponent(ScriptB);
	myScriptB.OpenMainDoor();
}

Unfortunately I get this error

NullReferenceException: Object reference not set to an instance of an object

Your myScriptB variable is null. Check if the GetComponent function actually returns the component before trying to call a function in it. Chances are that you gameObject doesn’t have a ScriptB component.

 confirmButton.onClick.AddListener(MyConfirmFunctiom);
 
 function MyConfirmFunctiom(){
     var myScriptB:ScriptB=GetComponent(ScriptB);
     if(myScriptB != null) {
         myScriptB.OpenMainDoor();
     }
     else {
         Debug.Log("" is null!");
    }
     
 }