Pause not working correctly

So I have this script:

var firstPersonController:Transform;
var lantern:GameObject;
var paused : boolean = false;
function Start () {
inventoryText.guiText.text = "";
}

function Update () {
 if (Input.GetKeyDown("p")&& paused == true){
        inventoryText.guiText.text = "Lantern " + "[" + inventoryArray[0] + "]" + "

"+ “Hit H to equip!”;
//inventoryArray[0]++;
//inventoryArray[1] += 2;
paused = true;
if (Time.timeScale == 1.0)
Time.timeScale = 0.0;
}
if (paused == false){
inventoryText.guiText.text = “”;
Time.timeScale = 1.0;
}
if (Input.GetKeyDown(“h”) && inventoryArray[0] > 0){
var go = Instantiate(lantern) as GameObject;
go.transform.parent = firstPersonController;

          inventoryArray[0] -= 1;
      }
      if (Input.GetKeyDown("p")){
        inventoryText.guiText.text = "Lantern " + "[" + inventoryArray[0] + "]" + "

"+ “Hit H to equip!”;
//inventoryArray[0]++;
//inventoryArray[1] += 2;
}
}

I want to be able to hit “p” and have the game pause as well as show the inventory, then when I hit “p” again I want it to not be paused and not show the inventory. However the script right now just blinks with the guitext shown when I hit “p” rather than pause the way I want it to.

Add a return.

if (Input.GetKeyDown("p")&& paused == true){
         inventoryText.guiText.text = "Lantern " + "[" + inventoryArray[0] + "]" + "

"+ “Hit H to equip!”;
//inventoryArray[0]++;
//inventoryArray[1] += 2;
paused = true;
if (Time.timeScale == 1.0)
Time.timeScale = 0.0;
return; // ← here
}
But better to handle things in outside methods, IMO so you can call it from other places like so. Forgive me, I write in C# not javascript but here we go

var isPaused : bool = false;

function Update (){
    if(input.GetKeyDown(KeyCode.P)){
      if(isPause){
         UnpauseGame();
      } 
      else{ 
         PauseGame();
      }
    isPaused = !isPaused;
    }
}
function PauseGame(){
  InvantoryText.enabled = true;
  Time.timeScale = 0;
}

function UnpauseGame(){
  invantoryText.enabled = false;
  Time.timeScale = 1;
}