Solved. Code just stopped working

the error is cant define clone of null, but this exact code was working perfectly an hour ago any ideas\

var Spawner = pc.createScript('spawner');

// initialize code called once per entity
Spawner.prototype.initialize = function() {
    this.Spawner = 0;
    this.spawnedMonster = 0;

// update code called every frame
Spawner.prototype.update = function(dt) {
    this.Spawner += dt;
    if (this.Spawner > 5 && this.spawnedMonster < 1) {
         this.spawnedMonster = 1;
         this.Spawner = 0;

         var Monster1 ='Monster1');
    var F = Monster1.clone();
        F.rigidbody.teleport(-12, 1, -4);        
    if (this.Spawner > 15 && this.spawnedMonster < 2 )  {
         this.spawnedMonster = 2;
         this.Spawner = 0;
        var Monster2 ='Monster1');        
        this.G = Monster2.clone();
        this.G.rigidbody.teleport(-12, 1, -4);        

What changes have you made in the meantime?

none at all, i tried putting it into console and got nothing, restarted my pc but still

Can you share a project url?

the code is in the 2nd wall from the hierachy

The problem is in your HealthBar.js script, there you destroy() your Monster1 entity, so later when you try to spawn a copy of it, it’s not available. It throws an error Moster1 is null, check that.

interesting, when the healthbar is at 0 i want the cloned entity to dissapear, so i will try to teleport it instead of destroying it, i dont know why the Monster 1 is be affected as its boxed off not taking dmg, i will try it now

It’s affected because it has the HealthBar script attached, and the code executes on the attached entity:



ok, so i just reaaranged the order ,i set the scale first then used if, then destroy, but now the scale is not going down on contact lol