#Why does this run multiple times on players death? Resolved

1 messages · Page 1 of 1 (latest)

near flint
#

it repeats it a few times?

#
  system.runTimeout(() => {
                    world.scoreboard.getObjective('Deaths').addScore(killed, 1);

                    world.scoreboard.getObjective('Combat').setScore(killed, 0);
                    killed.removeTag("ffa");


                    world.scoreboard.getObjective('Kills').addScore(killer, 1);
                    killer.runCommandAsync('playsound random.orb @s');
                    world.scoreboard.getObjective('Streak').addScore(killer, 1);
                    world.scoreboard.getObjective('Combat').setScore(killer, 0);
                    world.scoreboard.getObjective('Combo').setScore(killer, 0);

                    // Resetting Streak for killed player
                    world.scoreboard.getObjective('Streak').setScore(killed, 0);
                    handleRankUp(killer)

                }, 0);


                const killerHasTagRDU = killer.hasTag('rdu');
                const killedHasTagRDU = killed.hasTag('rdu');

                let xpToAdd = calculateXpToAdd(killerRank, killedRank);

                if (killerHasTagRDU && killedHasTagRDU) {
                    // Double the xpToAdd if both have the tag "rdu"
                    xpToAdd *= 2;
                    killed.runCommandAsync(`scoreboard players remove @s XP ${xpToAdd}`)
                }
                const killerHasTagtf = killer.hasTag('tf');


                if (killerHasTagtf) {
                    xpToAdd /= 2;
                }
                const killerHasTagffa = killer.hasTag('ffa');
                if (killerHasTagffa) {
                    xpToAdd /= 10;

                }
                if (xpToAdd > 0) {
                    killer.runCommandAsync(`scoreboard players add @s XP ${xpToAdd}`);
                    killer.sendMessage(`§c+1 Kill\n§a+Xp ${xpToAdd}`);
                }

                killer.runCommandAsync('effect @s instant_health 1 255 true');
            }
        }
    });

raven void
#

i wonder why

#

theres totally not a playerDie event or anything

near flint
#

there is i just dont have nitro so message is to big

raven void
#

send it in a text fil

#

e

near flint
median fog
#
world.afterEvents.entityDie.subscribe(function (event) {
  if (!(event.deadEntity instanceof Player)) return
    const player = event.deadEntity;
    // do whatever
});
near flint
#

thanks tho

raven void
# near flint

probably because your kill event is in the entityHurt

#

so whenever an entity gets hurt itll run that

near flint
#

oh good point thanks

#

Why does this run multiple times on players death? Resolved

smoky sail
#

because the post is from 2023...

median fog
#

just try it, if it does it does, and if it doesn't create a new post asking how to do what you are trying to do

pearl orchid