This is probably super unoptimzied and messy. But I am trying to make it to where when an object with a "spawn" value is detected, the player can randomly spawn between these locations:
const spawns = world.getDimension('overworld').getEntities({ type: 'chaotic:multi' }).filter(e => e.getDynamicProperty('multiType') === 'spawn').sort(() => Math.random() - Math.random())
const rng = spawns.length;
const random2 = Math.floor(Math.random() * (rng - 1 + 1)) + 1
const spawn = spawns[random2]
const x = spawn.location.x
const y = spawn.location.y
const z = spawn.location.z
const dimension = world.getDimension('overworld')
player.camera.fade({ fadeColor: { red: 0, green: 0, blue: 0 }, fadeTime: { fadeInTime: 0, fadeOutTime: 1, holdTime: 0 } })
// if (players[spawnNumber]) players[spawnNumber].teleport({ x: x, y: y, z: z })
player.setSpawnPoint({dimension:dimension,x:x,y:y,z:z})
It's probably explanatory on what im trying to do, however this is really bad of an approach it seems because it sometimes doesen't change my spawn at all, fails to get entity locations, and other issues.