Updated Script:
#1250718489853821039 message
Old Script:
import { world } from '@minecraft/server';
function toTitleCase(str) {
return str.split(" ").map(w => `${w.charAt(0).toUpperCase()}${w.slice(1)}`).join(" ");
};
world.afterEvents.entityDie.subscribe(( { deadEntity } ) => {
const { x, y, z } = deadEntity.location;
if (deadEntity.typeId === 'minecraft:player') {
const deathDimension = deadEntity.dimension.id.replace('minecraft:','').replaceAll('_', ' ');
const formattedDimension = toTitleCase(deathDimension.charAt(0).toUpperCase() + deathDimension.slice(1));
world.sendMessage(`§6${deadEntity.name}§r has §cdied§r at §b${Math.trunc(x)}§r, §b${Math.trunc(y)}§r, §b${Math.trunc(z)}§r in §a${formattedDimension}§r`);
};
});
Using this script, you can get information of where the player died. When a player dies, A message will be sent, which displays coordinates and the dimension of the death location of the player.