How to give a template a dynamic variable in script

I was making a crafting system and I was wondering how I could make it so that the template for what you could craft would know what it should craft when you click on the text.

this is what I have so far for crafting the text template:


Craftable.prototype.onStateChanged = function(state) {  
    if (played == true){
    for (var i = this.entity.children.length - 1; i >= 0; i--) {
   this.entity.children[i].destroy();
}
    }
    const craftableItems = this.getCraftableItems();

        
    craftableItems.forEach(item => {
        let template = this.app.assets.find('Text');
        if (template) {
            
            var text = template.resource.instantiate();
            let capitalizedName = Helper.capitalizeEveryWord(item.name)
            text.element.text = capitalizedName
            
            this.entity.addChild(text);
            
            
        }
    });      
    played = true
    
};

Hi @Literally_Kirby!

I think I have some idea of ​​what you’re trying to achieve, but it’s not clear to me what in your script is not working or missing.

Could you please rephrase your question?

like I want the text template to have a variable called to craft and it will tell the text entity what to give the player onClick

or I should probably how do I change a this variable from a different script

If you know the entity and script name that has the variable, it should be something like below.

entity.script.scriptName.variableName += 1;

Thanks I figured it literally as I saw you typing lmao.