#LvL Up events

1 messages Β· Page 1 of 1 (latest)

sleek crypt
#

How can I make a command play everytime a player levels up? I mean when the player levels up with xp, the vanilla level up system

azure hearth
#

there's some issues with this where it would also trigger if you die.

stiff forum
sleek crypt
#
import { world } from "@minecraft/server";

system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
        if (player.lastLevel === undefined) {
            player.lastLevel = player.level
        }
        if (player.level !== player.lastLevel) {
            player.lastLevel = undefined;
            player.sendMessage('you leveled up')
        }
    }
})
#

@azure hearth why this isn't working?

#

There oe something wrong on the way that I put the code?

stiff forum
sleek crypt
#

I forgot to look

#

But the structure of the js is right?

azure hearth
#

because it works for me.

#

and its all stable.

azure hearth
#

thank you

sleek crypt
#

@azure hearth can you make me a full js with this?

#

I'm bad at scripting

azure hearth
#

it is full.

#

well it doesn't have the imports, if that's what you mean...

azure hearth
#

you didnt import system...

#

this is why you need to look at your content logs, and have them on if you dont.
or just make sure you import things you need.

#
import { world, system } from "@minecraft/server";

system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
        if (player.lastLevel === undefined) {
            player.lastLevel = player.level
        }
        if (player.level > player.lastLevel) {
            player.lastLevel = undefined;
            player.sendMessage('you leveled up')
        }
    }
})

world.afterEvents.playerSpawn.subscribe(data => {
    const player = data.player
    player.lastLevel = undefined
})```
sleek crypt
azure hearth
azure hearth
#

I sent the script above.

#

then learn.

sleek crypt
#

I really need a full script tutorial

azure hearth
#

you can just look up the script api documents and basic javascript tutorials

#

and look at what people already made here for reference...

sleek crypt
#

hey, idk why but the script somethimes just stop working, and it didnt leave any erros

#

what it can be?

high mist