Is my code correct?

I’m trying to make a trigger script but it just doesn’t work!

var TrigKill = pc.createScript('Trigkill');
TrigKill.attributes.add('kill', {type : 'entity'});

// initialize code called once per entity
TrigKill.prototype.initialize = function() {
    this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
    this.entity.collision.on('triggerleave', this.onTriggerLeave, this);
};

TrigKill.prototype.onTriggerEnter = function(otherEntity) {
    if (otherEntity.name === 'Player') {
        this.kill.enabled = false;
    }
};

TrigKill.prototype.onTriggerLeave = function(otherEntity) {
    if (otherEntity.name === 'Player') {
        this.kill.enabled = true;
    }
};

// update code called every frame
TrigKill.prototype.update = function(dt) {

};

Hi @Brent_Reddick1! :waving_hand:

Your code looks correct to me, so the problem is probably somewhere in your setup.

Are you able to share the editor link of your project so I can take a look?

I fixed the issue, thanks!

Thanks for your reply!

Please share your solution to make this topic useful for other users who may have the same issue.