Value doesn't change in game when updated.

I have two scripts one called score, which calculates the score then converts it to a string. The other script is called Score Multiplier, that updates the multiplier value in the score script when I pick up the multiplier object.

Score Script:

public float score = 0.0f;
    public float defaultScore;
    public float multiplierScore;
    public float multiplierNum = 0;
    public TextMeshProUGUI prefab;
    void Update()
        defaultScore = Time.deltaTime * 15;
        multiplierScore = defaultScore *= multiplierNum;
        score += multiplierScore;
        prefab.text = ((int)score).ToString("0000000");

Score Multiplier script:

public GameObject pickupEffect;
    public GameObject Score;
    public float duration = 10f;

    public void OnTriggerEnter2D(Collider2D other)
        if (other.CompareTag("Player"))

    public void PickUp()
        Instantiate(pickupEffect, transform.position, Quaternion.identity);

        Score multiplier = Score.GetComponent<Score>();
        multiplier.multiplierNum = 1000;


So when the player collides with the multiplier object the multiplierNum float value should update to 1000. Instead the value updates when I restart the game or when I die and respawn.

This is the respawn code in the player controller:

if (health <= 0)

I just started using unity and coding about 4 days ago so please make your responses nood friendly.


the only solutions i can think of is finding the object in the scene, or savint the multiplier value in playerprefs for example, and access the playerprefs whenever you need it.

@alexpensotti - I saw in your comment earlier you asked about updating the value of a prefab… I assume you mean after having instantiated it… there’s a couple ways to do this. Let’s assume your variable is public… so… here’s one way…

GameObject MyCopy = Instantiate(//the prefab) as GameObject;
MyCopy.GetComponent<ScriptOnObject>().VariableToChange = newValue;