Upgrades not applying after first death

Ok so I’ve got a space-shooter type game I’ve been making in my spare time, trying to learn how to use unity and script in js. Now I’ve recently run into an issue. I have a powerup that spawns from random dead enemies. I can pick it up, and it properly applies to my ship, enhancing the weapon. It has multiple upgrades based on the animation it shows when you pick it up, that works fine. However, after you die once, the powerups do not work. You can pick them up sure, but they aren’t being applied to the player, they just vanish.

Not really sure where to look. I have a feeling I’m doing the respawn script wrong, it’s making a new copy of the player and maybe it should somehow reuse the last instance of my player, how would I do that?

I can post some code segments, not sure where the culprit is so not really sure what to post.

Wait, I think I found it…
So at start you get a reference to a GameObject tagged “wep_up”:

upgrade = GameObject.FindGameObjectWithTag("wep_up").GetComponent(upgrade_script);

Then when you collide with it, you go ahead and destroy it at the very bottom:

if (col.gameObject.tag == "wep_up"){
		if (upgrade.PowType == 1){
			if (wep1 == false){		
				wep1 = true;
				wep2 = false;
				wep3 = false;
				PowLvl = 1;
			}
			else{
				PowLvl++;
			
			}
		}
		if (upgrade.PowType == 2){
			if (wep2 == false){		
				wep1 = false;
				wep2 = true;
				wep3 = false;
				PowLvl = 1;
			}
			else{
				PowLvl++;
			
			}
		}
		if (upgrade.PowType == 3){
			if (wep3 == false){		
				wep1 = false;
				wep2 = false;
				wep3 = true;
				PowLvl = 1;
			}
			else{
				PowLvl++;
			
			}
		
		
		}
		Instantiate(shield_pref, Vector3(transform.position.x,transform.position.y, 2), Quaternion.identity);
		shield_pref.particleSystem.Emit == true;
		Destroy(col.gameObject);
	}

But you never get another reference to the upgrade. Can place this code real quick right after the “wep_up” condition passes.

upgrade = col.gameObject.GetComponent(upgrade_script);

Yes, I instantiate the prefab. The new instance is as I want it, however as I said, it won’t take the new powerups. Here are the scripts, I hope they’re not too messy because I had to copy/paste everything into notepad because this site was bugging out for me.

The powerup spawns by chance when you kill enemies: (part of the laser_script, a component of the laser itself.)

if (col.gameObject.tag =="Enemy"){
    manager.ShipsKilled++; 
    manager.points = manager.points + 100; 
    number = Random.Range(minRNG, maxRNG);
    if (number == 1) {
    	number = Random.Range(minRNG, maxRNG);
    	if (number > 5){ //if roll is higher than 5, spawn shield, if less than, spawn wep powerup, min/max default is 1/10
            Instantiate(shield_powerup,transform.position,Quaternion.identity);
    	}
    	if (number < 5){
    	    Instantiate(wep_powerup,transform.position,Quaternion.identity);
    	}
  }
  	Instantiate(enemydeath_pref, Vector3(transform.position.x,transform.position.y, 2), Quaternion.identity); //spawns particle emmiter on death
   	enemydeath_pref.particleSystem.Emit == true;
    	Destroy(col.gameObject); //destroy the enemy ship
  if(player.wep2 == false){
     Destroy(gameObject); // destroy the weapon particle if it's not wep2.
  }
}

aaaand to apply/delete the power up: (this is a part of the playerscript, a component of the player)

 if (col.gameObject.tag == "wep_up"){
    		if (upgrade.PowType == 1){ 
    			if (wep1 == false){		
    				wep1 = true;
    				wep2 = false;
    				wep3 = false;
    				PowLvl = 1;
    			}
    			else{
    				PowLvl++;
    			
    			}
    		}
    		if (upgrade.PowType == 2){
    			if (wep2 == false){		
    				wep1 = false;
    				wep2 = true;
    				wep3 = false;
    				PowLvl = 1;
    			}
    			else{
    				PowLvl++;
    			
    			}
    		}
    		if (upgrade.PowType == 3){
    			if (wep3 == false){		
    				wep1 = false;
    				wep2 = false;
    				wep3 = true;
    				PowLvl = 1;
    			}
    			else{
    				PowLvl++;
    			
    			}
    		
    		
    		}
    		Instantiate(shield_pref, Vector3(transform.position.x,transform.position.y, 2), Quaternion.identity);
    		shield_pref.particleSystem.Emit == true;
    		Destroy(col.gameObject);
    	}

When hit by an enemy ship or projectile, player death: (playerscript agian)

 if (col.gameObject.tag == "Enemy" || col.gameObject.tag == "Boss_Shot" || col.gameObject.tag == "asteroid"){
    			Destroy(col.gameObject);
    			if (Shield == true){ //if you have a shield, adjust the player texture on hit to remove the shield
    				renderer.material.mainTextureOffset = Vector2(0.0,0.5);
    				Instantiate(shield_die, Vector3(transform.position.x,transform.position.y, 2), Quaternion.identity); //play an effect when the shield dies
    				shield_die.particleSystem.Emit == true;
    				Shield = false; //boolean disable the shield
    				return;
    			}
    		manager.deathTime = Time.time; //add a brief delay after death
    		manager.deathTimer = false;
    		Destroy(gameObject); // destroy the player
    		Explosion_Pref.particleSystem.Emit == true; //spawn a particle on death
    		Instantiate(Explosion_Pref, Vector3(transform.position.x,transform.position.y, 2), Quaternion.identity);
    	}

To respawn the player: (this is the managerscript, located in a “gamemanager” emptyobject so it is always present)

if (player == null && playerLives >= 1 && deathTime == 0){
		playerLives --;
		Instantiate(playerShip, Vector3(0,-4.5,2), Quaternion.identity);
		player = GameObject.FindGameObjectWithTag("Player");
		spawn_pref.particleSystem.Emit == true;
		Instantiate(spawn_pref, Vector3(0,-4.5, 2), Quaternion.identity);
	}

	if (player == null && playerLives >= 1 && deathTime > 0 && deathTimer == false){
		respawn();
	}

and the respawn() function:

	function respawn(){
			deathTimer = true;
			yield WaitForSeconds(1);
			playerLives --;
			Instantiate(playerShip, Vector3(0,-4.5,2), Quaternion.identity);
			player = GameObject.FindGameObjectWithTag("Player");			
			player.collider.isTrigger = true;
			spawn_pref.particleSystem.Emit == true;
			Instantiate(spawn_pref, Vector3(0,-4.5, 2), Quaternion.identity);
			yield WaitForSeconds(1.5);
			player.collider.isTrigger = false;
			
}