Update variable on player gameobject from other gameobject problem

I’ve scoured the references but I think i’m overlooking something but i’m asking whats the best way to do this.
Example
Player swings axe and hits tree. Timber value in player_inventory is updated with += 1.

Now I can do something similar like collecting an object off the ground with no problem but only because the player_inventory script and this collection script is both on the player.

I was planning on having the tree/enemy update/access the players variables but if I can somehow do that on the player that would work I guess.

Collection.js

var PlayerInventoryInstance;

  function Start () {
   PlayerInventoryInstance = GetComponent(Player_Inventory);
}

function OnTriggerEnter(col : Collider){
   if(col.tag == "Collection"){
   
     Destroy(col.gameObject);
     PlayerInventoryInstance.players_money += 10;
}

When I essentially have the collection script on the enemy/tree, that’s when I have problems. I’m asking if anyone can show me a small example put together or walk me through it because I see examples but somethings not clicking.

p.s. My character is spawned after the game is started so a gameobject.find on function start won’t work when doing a gameobject.find and get component from found gameobject.

Could you explain, very simply, what the issue is/what you need to happen or not happen

I’m trying to modify a var on my player from another object (Tree). When my axe col comes into contact with a tree, the tree see’s this and updates its hp accordingly. Then I want to add +1 to my timber variable on my player

I don’t know how I can get the script on the tree to access my timber value on my player and update it. I’m wondering if this is the correct approach and if it can work how to set it up. I’m pretty sure its just a few lines of getting the player and its component and updating the value but i’ve always had issues with this so I set it aside till now.

What you’re doing should be fine. You could make a script for the tree kinda like this:

function OnCollisionEnter (col : Collision)
{
     if (col.gameObject.tag == axe)
     {
          var player = col.gameObject.GetComponent(YourPlayerScript);
          player.woodAmount += 1;
     }
}

Edit: Alright I understand referencing a bit more. I got it working setting the timber to a static var (and attaching a script to my spawned weapon) but when I have 2 players connected i’m pretty sure they are going to share this value but atleast I have a better understanding of this. (nm it seems both characters aren’t sharing wood like I thought) I’m sure i still need to tweak it to get the correct instances but i’ll figure it out.

-Disregard for now. Hm, yeah this is where i’m having the problem. I’ve tried that before but i’m getting object reference not set to an instance of an object. I sort of have a grasp on referencing but in this occasion i’m a little stumped.