I have some problems with typescripts cospace. About create clone and Time.scheduleRepeating

This is my code

var block = Scene.getItem(“GXwbQcTX”) as Cuboid
var cam = Scene.getItem(“uz2WEg76”) as CameraItem

Time.scheduleRepeating(()=>{
let clone = block.copy()
Time.scheduleRepeating(()=>{
let CamPos = cam.transform.position
clone.transition.moveTo(CamPos,1)
},1)
Time.schedule(()=>{
clone.delete()
},1)
},0.5)

And output show me this:

Is very lag , pls help me to fix that . thank

1 Like

Hi @HenryHuy we’ve had a look at your script and it’s not working correctly because the script is trying to move an item that has previously been deleted.

You can try this script:

var block = Scene.getItem(“4AbfhwhL”) as Cuboid;
var cam = Scene.getItem(“HmjM1giz”) as CameraItem;
if (!block) {
    throw new Error(“Block not found with ID 4AbfhwhL”);
}
if (!cam) {
    throw new Error(“Camera not found with ID HmjM1giz”);
}
function createAndMoveClone() {
    try {
        let clone = block.copy();
        let camPos = cam.transform.position;
        clone.transition.moveTo(camPos, 1);
        Time.schedule(() => {
            clone.delete();
        }, 1);
    } catch (error) {
        console.error(“Error in createAndMoveClone:“, error);
    }
}
try {
    Time.scheduleRepeating(createAndMoveClone, 0.5);
} catch (error) {
    console.error(“Error in scheduleRepeating:“, error);
}

Let us know if this works for you!

Have a nice Friday and weekend! :slight_smile:

3 Likes

Thank you !!! :slight_smile:
Am will try now .
Have nice day .

1 Like

Is work very well , thank you so much !!! :slight_smile:

1 Like