please help me with my lives not updating properly 2d platformer

I’m trying to get my number of lives to update properly. Here is my code:

using UnityEngine.SceneManagement;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DetectCollision:MonoBehaviour
{
int score,nbLives,nbCoinsCollectedPerLevel;
// Start is called before the first frame update
void Start()
{
nbCoinsCollectedPerLevel = 0;   
}
// Update is called once per frame
void Update()
{   
}
void OnCollisionEnter2D(Collision2D coll)
{
string tagName=coll.collider.gameObject.tag;
if(tagName=="pick_me")
{
Destroy(coll.collider.gameObject);

//score++;
score = PlayerPrefs.GetInt("score");
score++;
PlayerPrefs.SetInt("score",score);

nbCoinsCollectedPerLevel++;
if(SceneManager.GetActiveScene().name=="level1"&&nbCoinsCollectedPerLevel>=5)
{
SceneManager.LoadScene("level2");
}
print("score" + score);
}
if (tagName == "avoid_me" || tagName == "reStarter")
{
Destroy(coll.collider.gameObject);
nbLives = PlayerPrefs.GetInt("nbLives"); 
 nbLives--; 
 PlayerPrefs.SetInt("nbLives", nbLives); 
 if (nbLives >= 0) 
SceneManager.LoadScene(SceneManager.GetActiveScene().name); 
 else SceneManager.LoadScene("lose"); 
 print ("lives" + nbLives); 
}
if(tagName=="endOfLevelTwo")
{
SceneManager.LoadScene("win");
}
}
}

And here is the code that loads the lives in the splash screen scene:

using UnityEngine;
using System.Collections;

public class initGame : MonoBehaviour {

	// Use this for initialization
	void Start () 
	{
		PlayerPrefs.SetInt ("score", 0);
		PlayerPrefs.SetInt ("nbLives", 3);

	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

What is wrong with my code?

Please help.

Thanks.

nstruth

What is exactly is the problem with the lives?
My guess is that the lives are not being imported properly into the next scene because everytime you load up the characters in the start method, you are resetting the PlayerPrefs “nbLives” back to 3. So whatever happened previously doesn’t matter because you are always setting them to 3 in the start method.