I am sorry to disturb you again i have wrote a script but i cant seem to make it work i am sorry i am new with JS not very experienced if thatâ€™s the case in my script but can you have look on it and see if i did something wrong?

iâ€™ve tried to look around alot but i cant seem to understand why i cant call any tilesets

```
let splitTilesets = tiled.registerAction('SplitTilesets', function (action) {
const tileSets = TileMap.usedTilesets;
let tileSize = Tileset.tileSize;
let tileLayers = [];
const mapSize = TileMap.size;
for (let i = 0; i < TileMap.layerCount; i++) {
tileLayers.push(TileMap.layerAt(i))
}
//for (let i = 0; i < tileSetscount; i++) {
let i = 0;
let topLeftTileset = tiled.open(tileSets[i].fileName + "-1")
let topRightTileset = tiled.open(tileSets[i].fileName + "-2")
let bottomRightTileset = tiled.open(tileSets[i].fileName + "-3")
let bottomLeftTileset = tiled.open(tileSets[i].fileName + "-4")
TileMap.addTileset(topLeftTileset)
TileMap.addTileset(topRightTileset)
TileMap.addTileset(bottomRightTileset)
TileMap.addTileset(bottomLeftTileset)
for (let j = 0; j < tileLayers.length; j++) {
if (tileLayers[j].isTileLayer) {
for (let x = 0; x <= mapSize * tileSize; x++) {
for (let y = 0; y <= mapSize * tileSize; y++) {
initNewTileID(x * tileSize, y * tileSize, tileLayers[j], tileSets[i], tileSets[i].imageHeight, tileSets[i].imageWidth,
topLeftTileset, topRightTileset, bottomLeftTileset, bottomRightTileset)
}
}
}
}
//}
})
splitTilesets.text = "Split Tilesets";
tiled.extendMenu("Map", [
{separator: true},
{action: "SplitTilesets"},
])
function initNewTileID(mapX, mapY, layer, oldTileset, oldTilesetHeight,
oldTilesetWidth, topLeftTileset, topRightTileset, bottomLeftTileset, bottomRightTileset) {
let oldTile = layer.tileAt(mapX, mapY);
//get the x, y of the tile in the tileset:
let tileX = oldTile.id % oldTilesetWidth;
let tileY = Math.floor(oldTile.id / oldTilesetHeight);
let newTileset;
if (tileX < oldTilesetWidth / 2) {
if (tileY < oldTilesetHeight / 2)
newTileset = topLeftTileset;
else
newTileset = bottomLeftTileset;
} else {
if (tileY < oldTilesetHeight / 2)
newTileset = topRightTileset;
else
newTileset = bottomRightTileset;
}
//Get the tile's location within the new tileset:
tileX = tileX % Math.floor(oldTilesetWidth / 2);
tileY = tileY % Math.floor(oldTilesetHeight / 2);
//Now we know what tileset to use, and the tile's location in that tileset. From the location, we can calculate the new tile ID:
let newTileID = tileX + tileY * floor(oldTilesetWidth / 2);
//And now we can get the tile to replace the old one with:
let newTile = newTileset.tile(newTileID);
TileLayerEdit.setTile(mapX, mapY, newTile, oldTile.flag)
TileLayerEdit.apply()
TileMap.removeTileset(oldTileset)
}
```