How to make a trigger change a variable by +1 once an objects leaves it?

I’m trying to make a game where when a ball goes through a hoop and passes through a trigger it changes a score variable by +1 and updates a text thing to display the score. When the ball passes through it I’m also trying to make the trigger teleport the ball to the center of the map. I have started a script to teleport the ball I found from another forum but I could not get it to work.

What I have so far:

var Teleport = pc.createScript('teleport');

// initialize code called once per entity
Teleport.prototype.initialize = function () {
    this.entity.collision.on('triggerleave', this.onTriggerLeave, this);
    console.log('did thing');
    this.teleportPoint = this.app.root.findByName('TeleportPoint');
};

Teleport.prototype.onTriggerleave = function (result) {
    if (result.other.rigidbody) {        result.other.rigidbody.teleport(teleportPoint);
    }
};

Would appreciate help thanks

Hi @Finlay_Dewar and welcome!

On line 11 of the script above teleportPoint need to be this.teleportPoint.

You need to create a child entity of the 2D screen and add a element component of type text. You probably also need to upload a font and assign it to the component. On the script you can create a reference to the entity, like you do on line 7 of the script above for the teleport point.