Stats effecting the max Health Value

What I want to do here is change the MaxHealth Value each time the “Vitality Stat” Value changes. For example
Maxhealth = 100 + (Vitality * 8); (This would give me an error message because I would do this.

PlayerStats playerStats;

public float MaxHealth = 100 + (playerStats.Vitality * 8);

public void Start{
     ETC....
}

This would give me a weird error message.
Then I tried to do.
public float maxHealth;

    void Start ()
    {
		maxHealth = (100 + (playerStats.Vitatlity * 8) / 2);
        currentHealth = maxHealth;
        currentMana = maxMana;

    }

This wouldnt Work either… And i also tried it in in the Update method which seemed more correct but still it didnt do what i wanted it to doo!

Here are my 2 scripts that are needed for this to hopefully work.

public class PlayerHealth : MonoBehaviour {

	PlayerStats playerStats;

    public float currentHealth;
	public float maxHealth;
    public Slider playerHealthBar;
    public int healthRegen = 4;

    public float currentMana;
    public float maxMana = 1000;
    public Slider playerManaBar;
    public int manaRegen = 12;


    CharacterController playerMovement;
    private bool isDead;


    void Start ()
	{
        currentHealth = maxHealth;
        currentMana = maxMana;

    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Minus))
            DealDamage(6);
        if (Input.GetKeyDown(KeyCode.Period))
            UseMana(52);

        if (currentHealth < maxHealth)
            currentHealth += healthRegen * Time.deltaTime;

        if (currentMana < maxMana)
            currentMana += manaRegen * Time.deltaTime;


        if (currentHealth <= 0)
            KillPlayer();
    }

    public void DealDamage(int damageValue)
    {
        currentHealth -= damageValue;

    }

    public void SetMaxHealth()
    {
        currentHealth = maxHealth;
    }

    void UseMana(float manaUseValue)
    {
        currentMana -= manaUseValue;

        if (currentMana <= 0)
            currentMana = 0;
    }


    void KillPlayer()
    {
        Destroy(gameObject);
    }

}

public class PlayerStats : MonoBehaviour {

    public float Strength = 6;
    public float Vitatlity = 10;
    public float Agility = 6;
    public float Intellect = 6;


	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}

You need to instantiate the PlayerStats before you can access its properties

void Start ()
{
    playerStats = new PlayerStats(); // <-- THIS
    maxHealth = (100 + (playerStats.Vitatlity * 8) / 2);
    currentHealth = maxHealth;
    currentMana = maxMana; 
}

Also, if you are only using the PlayerStats to store the values (with some functions maybe), you don’t need the MonoBehaviour implementation.

public class PlayerStats
{
    public float Strength = 6;
    public float Vitatlity = 10;
    public float Agility = 6;
    public float Intellect = 6;
}

The PlayerStats class above will be enough. If you only need the properties, you can change the class to a struct.

@NightmareTD There is no need to inherit MonoBehaviour in PlayerStats. In this case playerStats is null and you need to instantiate PlayerStats component. Alternatively you can try this:

public class PlayerStats {
    public float Strength;
    public float Vitality;
    public float Agility;
    public float Intellect;

    public PlayerStats()
    {
     Strength = 6;
     Vitality = 10;
     Agility = 6;
     Intellect = 6;
    }
}

void Start ()
{
    playerStats = new PlayerStats();
    ...
}

To make sure please copy error message you received.