define a life counter first

var life_counter = 3;

and then code a function like this :-

function life _counter_dec()
{
life_counter -= 1;
IF(life_counter == 0) { death_panel.visible = on;}
}

death_panel is the panel shown after death(I hope you know what panels are,else
you can refer the manual)
On this panel add a button which can be clicked to load the mainmenu.

Hope it helps.
cheers!

zazang