[SOLVED] Problem with setting a value from other script

I set a value from another script on 100.
If i use a function with that same value the value is still 0.
I can’t figure out why…

    hit.other.parent.script.healthDamage = 100;
    console.log(hit.other.parent.script.healthDamage); < result is 100 >
    hit.other.parent.script.enemy.setHealth();
Enemy.prototype.setHealth = function () {
    console.log(this.healthDamage); < result is 0 >
};

hit.other.parent.script.healthDamage = 100

Here you are creating a new attribute on the script object rather than the enemy object.

Try:
hit.other.parent.script.enemy.healthDamage = 100

1 Like

Oops…