XP Lamp script not working

my level up script is working but my xp lamp isnt working here is the basic level up script:

var XP = 0;

var NeededXP = 100;
    
    //add a function OnGUI 
    
    if(XP == NeededXP);
    
    if(XP == 100)
    print("Level One Has Been Reached");

and here is my XP Lamp script:

@script RequireComponent(LevelScript);
var XP = 100;

function OnCollisionEnter(collision : Collision){
 XP += 100;


}

There’s two ways to approach this. The easy one is to make the variable XP a static variable, meaning it’s a single variable accessible from every script. Just replace var XP = 0; with static var XP = 0; and remove var XP = 0; from your Lamp script.

The other one is a bit more technical and requires some knowledge of scripting, but that can wait. See if this works first.

Well your Lamp script is only adding 100 to the XP variable on the script. You didn’t get your LevelScript’s XP variable. First make the XP variable on the level up script a static:

static var XP = 0;

Now get rid of your XP variable in the lamp script and make a call to get the LevelScript’s XP variable so it should look like this:

@script RequireComponent(LevelScript);

function OnCollisionEnter(collision : Collision){
 LevelScript.XP += 100;


}