I want to make a cps counter for my world but when I try this it doesn't seem to work. (1st image)
I'm also trying to display a player's own cps, but it ends up just showing the same thing for everyone in the actionbar. (2nd image)
import { world, system } from "@minecraft/server";
world.afterEvents.entityHitEntity.subscribe((data) => {
let damagingEntity = data.damagingEntity;
if (damagingEntity?.typeId !== "minecraft:player") return;
const amount = damagingEntity.getDynamicProperty("cps");
damagingEntity.setDynamicProperty("cps", amount + 1);
console.warn(amount)
system.runTimeout(() => {
damagingEntity.setDynamicProperty("cps", amount - 1);
}, 20);
});
//display
system.runInterval(() => {
world.getAllPlayers().forEach((damagingEntity) => {
const amount = damagingEntity.getDynamicProperty("cps");
damagingEntity.onScreenDisplay.setActionBar(amount)
});
});```