Coin and Life counter

Hi people,
I was wondering if anyone had any idea how to keep a canvas displaying a value like a coin counter keeping your coins between levels. Mine reverts to 0 when I switch levels and only corrects after picking up another coin. I’ll put the script i’m using below.
Coin Manager:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class CoinManager : MonoBehaviour
{
public static CoinManager instance;
public TextMeshProUGUI text;
static int coincount;
// Start is called before the first frame update
void Start()
{
if (instance == null)
{
instance = this;
}
}

public void ChangeScore(int coinValue)
{
coincount += coinValue;
text.text = “X” + coincount.ToString();
}
}
Coin Item:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Coin : MonoBehaviour
{
public int coinValue = 1;

void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag(“Player”))
{
CoinManager.instance.ChangeScore(coinValue);
Destroy(gameObject);
}
}

It’s essentially the same system I’m using for the players lives

Welp this is awkward. literally just copied the line
text.text = “X” + coincount.ToString();
to void start as well as where it already was.

Please use codetags, seems like this forum has been lately polluted by post from people who don’t read the rules how to post messages… is there still some problem or did you solve it?

Solved it, and I couldn’t or dont know how to use tags, it said I couldnt add new tags or something like that

That not that type of tag. When you’re editing a reply, up on the edit format part you’ll see a bunch of things (like B for Bold, I for Italics, and so on), among these you’ll see Code: followed by an icon. Press that icon, and it pops up an interface to add in code snippets like this:

public void SetSelectedPart(BuildingPart part)
    {
        DetailText.text = part.Description;
        DetailImage.sprite = part.Sprites[0];
        DetailImage.color = Color.white;
        if (selectedPartPlacmentGO == null)
            selectedPartPlacmentGO = Instantiate(GameResources.Current.BuildingPartPlacementPrefab);
        BuildingPartPlacementController bppc = selectedPartPlacmentGO.GetComponent<BuildingPartPlacementController>();
        bppc.BuildingPanelController_var = this;
        bppc.SetBuildingPart(part);
    }

@Kinfinite

“I couldn’t or dont know how to use tags…”

If you don’t know how, you should familiarize yourself with how the forum software works… this is the first pinned post in main scripting forum:

And yes, you can edit your post - so no need to wait until next post.

You have to refresh your coin count when it is created (when new scene is created)
i think if you will put this in Start() method will help:

Start()
{
text.text = coincount.ToString();
}