How to configure checkpoint

I added a checkpoint as object then made a script. It should work like this:
When player are in the checkpoint it should respawn a object.
I added the coordinates for the object to be spawned in but the object still doesnt spawn and i get no errors when launching the game.

Code:

var ObjectSpawner = pc.createScript('objectSpawner');

// Initialize the script
ObjectSpawner.prototype.initialize = function() {
    // Set the position for spawning the object
    var spawnPosition = new pc.Vec3(2.096, -2.846, -1.557); // Replace with your desired spawn position
    var objectName = 'barricade_smallWarehouse-2_0'; // Name of the object you want to spawn (use your actual model name)

    // Spawn the object immediately on initialization
    this.spawnObject(spawnPosition, objectName);
};

// Function to spawn an object
ObjectSpawner.prototype.spawnObject = function(position, objectName) {
    // Create a new entity for the spawned object
    var spawnedObject = new pc.Entity(objectName);
    spawnedObject.setPosition(position);

    // Add a model component (ensure the asset name is correct)
    spawnedObject.addComponent('model', {
        asset: this.app.assets.find(objectName + 'barricade_smallWarehouse-2_0') // Use your model name here (e.g., 'checkpoint.glb')
    });

    // Add the new entity to the scene
    this.app.root.addChild(spawnedObject);
    console.log('Object spawned at position:', position); // Log spawn position
};

// Optional update function (if needed)
ObjectSpawner.prototype.update = function(dt) {
    // Any logic to run every frame can be added here if needed
};

https://playcanvas.com/project/1264204/overview/wws

Hi @SarettiX !

Have you thought of cloning your object? It seems much easier that making a new object