#nothing happens when i kill a player

1 messages · Page 1 of 1 (latest)

brave wadi
#

Here, this should solve the issues you were experiencing.

import { world } from "@minecraft/server";

// Gets scoreboard objective. If undefined, adds it so it can be used.
const scoreboardKillstreak = world.scoreboard.getObjective("killstreak") ?? world.scoreboard.addObjective("killstreak", "killstreak");

world.afterEvents.entityDie.subscribe(evd => {
  const { deadEntity, damageSource } = evd;

  // This returns if deadEntity isn't a player, or the damageSource entity is undefined.
  if (deadEntity.typeId !== "minecraft:player" || !damageSource.damagingEntity) return;

  const player = damageSource.damagingEntity;

  scoreboardKillstreak.addScore(player, 1);

  const playerKS = scoreboardKillstreak.getScore(player);

  world.sendMessage(`${player.nameTag} now has a §¶§c§lkillstreak§r§f of ${playerKS}!`);
});
brave wadi
#

I wouldn't say anything was unnecessary, but glad it's working for you now.

#

Yeah, I know.