Referencing Foreign Variables

I have a problem with using a health variable from another script, which is right here:

    void Update()
    {
        if (health <= 0)
        {
            //Die();
        }
        healthConverted = (int)health;
        healthText.text = healthConverted.ToString();
        if (health == 0)
        {
            healthText.color = new Color(255, 0, 0);
            healthLabel.color = healthText.color;
        }
        if (health <= 60 && health != 0)
        {
            healthText.color = new Color(255, 255, 0);
            healthLabel.color = healthText.color;
        }
        if (health > 61)
        {
            healthText.color = new Color(0, 255, 0);
            healthLabel.color = healthText.color;
        }
    }

and using it in this script to apply damage:

 void Update()
    {
        if (time > timeLimit && !hasExploded)
        {
            Instantiate(explosion, bomb.transform.position, bomb.transform.rotation);
            Debug.Log("Explosion effect instantiated!");
            Collider[] colliders = Physics.OverlapSphere(bomb.transform.position, explosionRadius);
            foreach (Collider collider in colliders)
            {
                Rigidbody rb = collider.GetComponent<Rigidbody>();
                if (rb != null)
                {
                    rb.AddExplosionForce(explosiveForce, bomb.transform.position, explosionRadius);
                    if (collider.tag == "Player")
                    {
                        Component healthScript = player.GetComponent<Health>();

                    }
                }
            }
            hasExploded = true;
            Destroy(bomb);
        }
        else
        {
            time += Time.deltaTime;
        }

    }

How can I alter it from another script?

Seems like the first script is a Player object and the second one is a Bomb script.
Your Bomb script needs a reference to the Player and your player should have methods to do something with the health.

//player script
int health;

public void TakeDamage(int damage)
{
    health -= damage;
}

public int GetHealth()
{
    return health;
}


//bomb script
[SerializeField] Player player;

void Start()
{
    player = player.GetComponent<Player>();
}

if (collider.tag == "Player")
{
    player.TakeDamage(10);
}

Your issue is this line:

Component healthScript = player.GetComponent<Health>();

The problem is that you use GetComponent with your Health class (which is fine) but then you implicitly upcast the returned value to the base class Component. There you’re loosing all access to everything specific to your Health class. You have to declare your variable with the right type

Health healthScript = player.GetComponent<Health>();
healthScript.health -= xxx;

Even many people don’t like using the “var” keyword, it generally avoids such errors. Though you should only use “var” when it’s clear from the code what type is assigned to the variable. In out case we know that GetComponent<Health> returns a reference of type “Health”, so it’s fine to use:

var healthScript = player.GetComponent<Health>();
healthScript.health -= xxx;

This will implicitly type the variable healthScript as Health healthScript;

However you may want to consider something like what Vencarii·suggested. It’s generally better to implement a method inside the Health script to actually modify the health. That method can do some sanity checks as well as out of bounds checks. Also if any health change is handled with this method you can check for the death there as well. So there would be no need for the Update method anymore since you don’t have to update the text every frame, only when the health actually changed.