[SOLVED] Attribute setting its value to other attributes with same script

Im trying to make a shop where a player can touch a item and press g to purchase it. When the player collides with a item the cost correctly shows in the action text but when they press g all of the wrong info is sent to the server and the player is charged and given what they have not payed for.

var Purchasecrate = pc.createScript('purchasecrate');
Purchasecrate.attributes.add('cost',{type:"number"});
Purchasecrate.attributes.add('crateid',{type:"string"});
Purchasecrate.attributes.add('actiontext',{type:"entity"});
Purchasecrate.purchaseable=false;
// initialize code called once per entity
Purchasecrate.prototype.initialize = function() {
    this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};
Purchasecrate.prototype.onCollisionStart=function(result){
    if(result.other.tags.has('player')){
        this.actiontext.element.text=`Press [G] To Confirm Purchase Of ${this.cost} RT`;
        Purchasecrate.purchaseable=true;
        setTimeout(function(){
            this.actiontext.element.text=``;
            Purchasecrate.purchaseable=false;
        }.bind(this),5000);
    }
};
// update code called every frame
Purchasecrate.prototype.update = function(dt) {
   if(Purchasecrate.purchaseable){
             if(this.app.keyboard.wasPressed(pc.KEY_G)){
                Network.prototype.buycrate({"playfabid":localStorage.playerid,"skincrate":this.crateid,"cratecost":this.cost});
                console.log({"playfabid":localStorage.playerid,"skincrate":this.crateid,"cratecost":this.cost});
                this.actiontext.element.text=``;
                Purchasecrate.purchaseable=false;
        }
    }
};

The server code is correct and the network code is correct. Tested them. The client code is having the problem

The issue I see is that EVERY crate has this same script where it’s detecting if the pressed G.

In which case, it is possible that multiple creates can send data to the server.

Does the issue happen if there’s only one crate in the scene?

No one crate is fine. I might try change the script var to a local one

You may still have same problem as multiple crates could have purchaseable aa true if hte player touched multiple crates within 5 secs due to the timeout logic.

Ways that I would do this is to have a trigger per crate and track when the player enters and exits the trigger to know if they can buy it by pressing G

Or my preference would be to have a crate manager script that would keep track of the last crate that was collided with.

Changing the Purchasecrate to this worked thank you