Instantiate on click if enough gold / ressources

Hi there,
I have made an UI with some buttons and I’d like to instantiate things when i click those, but only if i have enough gold. Spawning works fine without the if statement

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

public class SpawnCreep : MonoBehaviour
{
    public GameObject Creep;
    public Transform Spawnpoint;
    public int Cost;
    private crntGold gold;

   

    
   
    public void SpawnThis()
    {
        
        //gold = GetComponent<crntGold>();
        

          //  if (gold.gold >= 10)
          //  {

                   Instantiate(Creep, Spawnpoint.position, Spawnpoint.rotation);
           //     gold.gold = gold.gold - Cost;

           //    }


    }


}

how come, and how could i change this? for sake of completeness, here is my gold script, maybe the error is there:

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

public class crntGold : MonoBehaviour
{
    public int gold;
    public Text uigold;
    private GoldCounter goldCounter;

    void Start()
    {
        gold = 100;
        uigold.text = "Gold:" + gold.ToString();
        goldCounter = GetComponent<GoldCounter>();
    }

    // Update is called once per frame
    void Update()
    {
        if (goldCounter.timer == 0.0f) ;
        { 
            
            uigold.text = "Gold:" + gold.ToString();
           
        }
        
    }
}

thanks for any replys in advance!

Hi there, @kaji0tt try to Debug.Log(); your gold.gold to check the actual value.

The Tab get component was opened for the last 15 hours, however it took me this time to realise, that i had to fetch the gold parameter with “gold = Manager.GetComponent();” with my script manager added to the button.

Thank you @Mr_parkour10021 for introducing me to debugging - probably this was the more efficent way of learning.