Changing game over message

I’m trying to add a message to my game over screen in a dice gambling game that will change based on whether or not the player wins, and which win condition they met.
I was trying a method similar to how I manipulate the players total coins and jackpot values, but it doesn’t seem to work.

var GameOverMessage = pc.createScript('gameOverMessage');

GameOverMessage.attributes.add('manager', {type: 'entity'});

// initialize code called once per entity
GameOverMessage.prototype.initialize = function()
{
    this.message = this.entity.findByName("GameOverTag");
    this.tag = this.manager.script.gameManager._tag;
    
    this.on('Enable', this.onEnable, this);
    this.on('Disable', this.onDisable, this);
    
    this.onEnable();
};

GameOverMessage.prototype.onEnable = function()
{
    this.app.on("game:gameover", this._changeTag, this);
    this._changeTag(this.tag);
};

GameOverMessage.prototype.onDisable = function()
{
    this.app.off("game:gameover", this._changeTag, this);
};

GameOverMessage.prototype._changeTag = function(newTag)
{
    this.message.element.text = newTag;
};

Every time I post a question lately I find the solution…

Never mind, problem came back. The second time the dice are rolled the toString comes back undefined.
This is what I’m attempting to do now:

var GameOverMessage = pc.createScript('gameOverMessage');

GameOverMessage.attributes.add('manager', {type: 'entity'});

// initialize code called once per entity
GameOverMessage.prototype.initialize = function()
{
    this.message = this.entity.findByName("GameOverTag");
    this.tag = this.manager.script.gameManager._tag;
    this.winnings = this.entity.findByName("RollWinnings");
    this.amount = this.manager.script.winCheck.winnings;
    
    this.on('Enable', this.onEnable, this);
    this.on('Disable', this.onDisable, this);
    
    this.onEnable();
};

GameOverMessage.prototype.onEnable = function()
{
    this.app.on("game:gameover", this._changeTag, this);
    this._changeTag(this.tag);
    this._changeAmount(this.amount);
};

GameOverMessage.prototype.onDisable = function()
{
    this.app.off("game:gameover", this._changeTag, this);
};

GameOverMessage.prototype._changeTag = function(newTag)
{
    this.message.element.text = newTag;
};

GameOverMessage.prototype._changeAmount = function(newAmt)
{
    this.winnings.element.text = newAmt;
};

Error appears on line 33 (this.message.element.text = newTag;.

are you sure that enable and disable events have the correct case?

this.on('enable', this.onEnable, this);
this.on('disable', this.onDisable, this);

Oddly enough, yes. I did initially have them with lower case and it didn’t work for some reason.

https://developer.playcanvas.com/en/user-manual/scripting/anatomy/

go at the end of the page. they are lowercase.

I understand that, I was following a tutorial to make the ui transitions and changes that had it that way, but it never worked when I tried it. And that’s not the issue I’m facing with this, the non existent toString call is returning an error.

Or maybe the lack of toString is the problem.

Nope, either way I get the error on the second roll.