items not retaining varibales when cloned

basicly i havea tree and ive got it so when it falls over an orange/apple is spawned but its spawend as a clone is there away to change it so its not a clone? also it dosent retain the variables player and other here is the scrpts also the item effect script keeps coming back with an error NullReferenceException: Object reference not set to an instance of an object
ItemEffect…ctor () (at Assets/Inventory/Scripts/Items/ItemEffect.js:2)

item effect put onto the apple

#pragma strict
var other : playerstats = player.GetComponent(playerstats);
//This script allows you to insert code when the Item is used (clicked on in the inventory).
var player : GameObject;
var deleteOnUse = true;

private var playersInv : Inventory;
private var item : Item;

@script AddComponentMenu ("Inventory/Items/Item Effect")
@script RequireComponent(Item)

//This is where we find the components we need
function Awake ()
{
	playersInv = FindObjectOfType(Inventory); //finding the players inv.
	if (playersInv == null)
	{
		Debug.LogWarning("No 'Inventory' found in game. The Item " + transform.name + " has been disabled for pickup (canGet = false).");
	}
	item = GetComponent(Item);
}

//This is called when the object should be used.
function UseEffect () 
{
	other.Hunger += 50; //INSERT CUSTOM CODE HERE!
	
	//Play a sound
	playersInv.gameObject.SendMessage("PlayDropItemSound", SendMessageOptions.DontRequireReceiver);
	
	//This will delete the item on use or remove 1 from the stack (if stackable).
	if (deleteOnUse == true)
	{
		DeleteUsedItem();
	}
}

//This takes care of deletion
function DeleteUsedItem()
{
	if (item.stack == 1) //Remove item
	{
		playersInv.RemoveItem(this.gameObject.transform);
	}
	else //Remove from stack
	{
		item.stack -= 1;
	}
	Debug.Log(item.name + " has been deleted on use");
}

spawn script and tree

#pragma strict
rigidbody.isKinematic = true;
var chop = 1000;
var FallingSound : AudioClip;
private var ChopStreak1 = 0;
private var ChopStreak2 = 0;
var treesounds : AudioClip ;
var fruit : Transform;
function ApplyDamage (Damage : int)
{	
	AudioSource.PlayClipAtPoint(treesounds,transform.position);
	chop -= Damage;
	if (chop == 300) 
	{
		Damaged();
	}
	if (chop <= 0)
	{
		 Dead();
	}
}
	




function Damaged()
{
		AudioSource.PlayClipAtPoint(FallingSound,transform.position);
		rigidbody.isKinematic = false;
		rigidbody.AddForce (Vector3.up * 20);
}

function Dead()
{
	Instantiate(fruit,transform.position, transform.rotation);
	Destroy (gameObject);
}

Your code in the item effect script is accessing the player variable before it is assigned on the second line which is probably causing your error. It should be reordered like this:

var player : GameObject;
var other : playerstats = player.GetComponent(playerstats);
//This script allows you to insert code when the Item is used (clicked on in the inventory).

Also make sure that the “fruit” that is assigned in the Editor is actually a GameObject that is live in the scene and not just a prefab in the Project.

As for the cloning, it will always be considered a “clone” because that’s exactly what Instantiate is doing. However the text “(Clone)” in the name is just so you know it’s different than the original GameObject that was cloned. You can simply use gameObject.name to rename it to whatever you want (perhaps “Fruit”).

I just saw this now. Try putting the playerstats line into your Awake() function like this:

var other : playerstats;

void Awake() {
    other = player.GetComponent(playerstats);
}

And also remove the Debug.Log statements.

Instead of just cloning, Instantiate it as GameObject. Or Use “object pooling” for optimized performance

function Dead()

{

    GameObject clone = Instantiate(fruit,transform.position, transform.rotation)as GameObject;

    Destroy (gameObject);

}