Multiple Objects with the Same Script

I have this code here which is supposed to add 4 to the total score after the card gets placed down on a section named “Placement”. This script is on two other objects that are the same card.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PotatoScore : MonoBehaviour {
	
    public int potatoTotal;
    public bool isPlaced;

    private void Start()
    {
        potatoTotal = 0;
        isPlaced = false;
}

    void Update ()
    {
        SetCostTotal();
        Debug.Log(potatoTotal);
    }

    void SetCostTotal()
    {
        if (this.transform.parent.name == "Placement" && Input.GetMouseButtonUp(0) && isPlaced == false)
        {
            potatoTotal += 4;
            isPlaced = true;
        }
    }
}

However, it will only add 4 for the first card that gets placed down. The other two cards don’t add 4 again like they should, even though isPlaced is still false for them. Why is this happening and what do I need to fix to get it to work properly?

I’m going to leave this here in case anyone else comes across this problem. The bool isPlaced variable was separate on each prefab but so were the potatoTotal variables. So each card started at 0 and added 4 to it’s own unique total, not the total potato score. The way to “fix” this is to add one little word.

static public int potatoTotal;

Adding static to the beginning makes it so that every instance or prefab of that card shares the same variable. Thus if the card is laid down, it adds 4 to the cumulative score, not the unique prefab score each card had.