Problems with a player spawning and handling script

Here’s the script,

var spawnpoints : GameObject [];

var isalive : boolean = true;
var playerprefab : GameObject;
var player : GameObject;

var Target : GameObject;

InvokeRepeating("checkalive", 0, 0.0001);

function checkifalive () {

	if(player.HP < 1){
	isalive == false;


function FindTarget () : GameObject {
		who = GameObject.FindWithTag("Finish"); //We have found a Target
	return who;

function Update () {
		Target = FindTarget(); return;

function respawn (){

yield WaitForSeconds(3);

	var index : int = Random.Range(1,spawnpoints.length);
    var thespawn : GameObject = spawnpoints[index];
    var instance : GameObject = Instantiate(playerprefab, thespawn, transform.rotation);
    player = instance;

    isalive == true;


there are two errors im encountering with this, and every time i think i fixed it, it gets worse, so I’ve stopped and resorted to unity answers and the guides.

How the script is supposed to work, is that the checkifalive function checks every one 10 thousandth of a second if the player gameobjects HP value is more than one. if it isnt, it checks the isalive boolean to false and respawns the player by using the playerprefab variable.

the respawn function supposedly should spawn the playerprefab randomly in one of the spawnpoints, and set the isalive value back to true.

there are two errors, the first is

Assets/scripts/Deathmatch/deathmatchHealth.js(19,17): BCE0034: Expressions in statements must only be executed for their side-effects.


Assets/scripts/Deathmatch/deathmatchHealth.js(52,44): BCE0023: No appropriate version of ‘UnityEngine.Object.Instantiate’ for the argument list ‘(UnityEngine.GameObject, UnityEngine.GameObject, UnityEngine.Quaternion)’ was found.

again, I’m not sure how to fix these without making it worse, any help is appreciated.

You have your Instantiate outside of a function, so it isn’t running.

So instead of this

InvokeRepeating("checkalive", 0, 0.0001);


function Start()
InvokeRepeating("checkalive", 0, 0.0001);

or just add checkalive(); to your Update function