Error when editing opacity of object

I get this error now when trying to edit the opacity of an object. I have looked at the documentation, and have now decided to resort to the forums.

Uncaught TypeError: Cannot set properties of undefined (setting ‘opacity’)

TypeError: Cannot set properties of undefined (setting ‘opacity’)
at ElementComponent. (https://launch.playcanvas.com/api/assets/files/Pawn.js?id=141493357&branchId=e6dbac65-52ca-41c1-a115-b310cb94b49a:50:68)
at ElementComponent.fire (https://code.playcanvas.com/playcanvas-1.64.3.js:598:18)
at ElementInput._fireEvent (https://code.playcanvas.com/playcanvas-1.64.3.js:69368:13)
at ElementInput._onElementMouseEvent (https://code.playcanvas.com/playcanvas-1.64.3.js:69273:12)
at ElementInput._handleUp (https://code.playcanvas.com/playcanvas-1.64.3.js:69121:9)

``
this.entity.element.on(‘click’, (event) => {
if (this.entity.tags.has(“white”)) {
this.app.root.findByTag(“SquareCover”).element.opacity = 0;
console.log(this.entity.getLocalPosition().x);
currentPieceClicked = event.element.entity.name;
console.log(‘The element ’ + this.entity.getLocalPosition() + “a” + ’ was clicked.’);

    if (Math.round(this.entity.getLocalPosition().x) < 2.999) {
        this.app.root.findByTag(getColumn(Math.round(this.entity.getLocalPosition().z)) + Math.round(getRank(this.entity.getLocalPosition().x))).element.opacity = 1;
        this.app.root.findByTag(getColumn(Math.round(this.entity.getLocalPosition().z)) + Math.round(getRank(this.entity.getLocalPosition().x))).element.opacity = 1;
        

        this.entity.translateLocal(this.entity.right.x, this.entity.up.y + 2, this.entity.forward.z);
    } else {
        if (Math.round(this.entity.getLocalPosition().x) <= 6.9999999999999999) {
            this.entity.translateLocal(this.entity.right.x, this.entity.up.y + 1, this.entity.forward.z);
            console.log(Math.round(this.entity.getLocalPosition().x));
        }
    }

``

for some reason the code outline doesnt work, so just start from the this.entity.element.on… … … . .

Hi @Lucas_Yu,

findByTag() returns an array, a list of entities. So if you are looking for the first tagged entity try doing this instead:

this.app.root.findByTag(“SquareCover”)[0].element.opacity = 0;

https://developer.playcanvas.com/en/api/pc.Entity.html#findByTag