how to display a message after the player has died more then 3 times

Hi I need help on a script that when the player dies more then 3 times it displays a gui text.

please help thanks,

int playerDeaths = 0;

when player dies =

playerDeaths++;

somewhere =
OnGUI()
{
if(playerDeaths == 3)
{
GUI.Box(new Rect(<>, “You have died 3 times, you are a noob”);
}
}

Regarding to the error messages delete the following:

when player dies :

Try this. I’ve made it so you can set the width, height and position of the text box in the inspector, so you can play around with those numbers until you get something you like.

var playerDeaths : int = 0;
var playerHealth : int = 100;
var maximumHealth : int = 100;
var textXPosition : int = 580;
var textYPosition : int = 350;
var textBoxWidth : int = 100;
var textBoxHeight : int = 20;
var damage : int;
var healAmount : int;

function Update () {
	
	
	// Limit the player's health to the maximum value
	if (playerHealth > maximumHealth)
	{
		playerHealth = maximumHealth;
	}
	
	// Limit the number of times the player can die to 3 (Just to be safe)
	if (playerDeaths > 3)
	{
		playerDeaths = 3;
	}
	
	// Set the minimum amount of health to 0 (If you don't do this, the player's health
	// might continue decreasing into the negatives even after they are killed)
	if (playerHealth < 0)
	{
		playerHealth = 0;
	}
	
	// When the player's health reaches 0, add 1 to the death count
	if (playerHealth == 0 && playerDeaths < 3)
	{
		playerHealth = maximumHealth;
		playerDeaths += 1;
	}
}

function OnGUI() { 

	// If the death count is above OR equal to 3, display the text (Make sure you do this
	// even if the death count goes over 3, because sometimes this happens, and obviously
	// you still want the player to die)
	if (playerDeaths >= 3) 
	{
		GUI.TextField (Rect (textXPosition,textYPosition,textBoxWidth,textBoxHeight), "Enter Text Here");
	}
}

function DecreaseHealth(damage : int) {

	playerHealth -= damage;
}

function IncreaseHealth(healAmount : int) {

	playerHealth += healAmount;
}

Then in a different script, you would call the health functions and specify how much to add or subtract. For example:

var damage = false;
var heal = false;
var player: GameObject;
var attackDamage : int = 5;
var healAmount : int = 5;

function Start () {

}

function Update () {

playerScript = player.GetComponent("Exact name of the health script");

// You would also add code in this function that would make the damage or heal variables
// true or false, depending on whether you want the player to be hurt or healed. If this
// script is attached to an enemy, you could check to see if their attack animation is
// enabled, and if it is, then change damage to true.

	if (damage == true)
	{
		playerScript.DecreaseHealth(attackDamage);
		damage = false;
	}
	
	if (heal == true)
	{
		playerScript.IncreaseHealth(healAmount);
		heal = false;
	}
}

To check if an animation is playing, use:

if (animation["Your Animation"].enabled)