Failing to get specific player data


Ticket #C7C5F169💬 14 â€¢ 1.20.1 â€¢ ForgeView on Discord 🡵

MarkSDR (Marcos) 

I need to add slowness when Survive Temperature get over 38, what i'm doing wrong? Script:
ServerEvents.tick(event => {

    const temperatureLevel = event.player.persistentData.ForgeData.survive.PlayerData.TemperatureStats.temperatureLevel;

    if (temperatureLevel && temperatureLevel > 38) {
        event.player.potionEffects.add("minecraft:slowness", 100, 0);
    }

});

PigTurtle 

persistantData is only data you set yourself through kubejs. You're looking for nbt, so just replace the ... .persistantData ... with ... .nbt ....

MarkSDR (Marcos) 

Thanks! I'll try it

MarkSDR (Marcos) 

of, i've changed the recipe to
ServerEvents.tick(event => {

    const temperatureLevel = event.player.nbt.ForgeData.survive.PlayerData.TemperatureStats.temperatureLevel;

    if (temperatureLevel > 38) {
        event.server.runCommandSilent('effect give @p minecraft:slowness 100 0')
    }

});
And now i'm getting this error:

[View image.png]

Atticool 

try PlayerEvents.tick() instead
ServerEvents doesn't have a player

MarkSDR (Marcos) 

Yeah, i did changed it and another stuff and had no error, but it doesn't applied the slowness:
PlayerEvents.tick(player => {


    const surviveData = event.player.nbt.ForgeData['survive:PlayerData'];
    const temperatureLevel = surviveData.TemperatureStats.temperatureLevel


    if (temperatureLevel >= 38) {

        player.potionEffects.add("minecraft:slowness", 100, 0);
        return
    }

});

Arp 

Not sure but try
PlayerEvents.tick(event  => {


    const surviveData = event.player.nbt.ForgeData['survive:PlayerData'];
    const temperatureLevel = surviveData.TemperatureStats.temperatureLevel


    if (temperatureLevel >= 38) {

        event.player.potionEffects.add("minecraft:slowness", 100, 0);
        return
    }

});

Atticool 

try using console.log and log each player its iterating on just so you can see what’s going on
↶ Replying to MarkSDR (Marcos) : Yeah, i did changed it and another stuff and had no error, but it doesn't applied the slowness: ```JS PlayerEvents.tick(player => { const sur…

WhiseNT 

You used "player" instead of "event" so in this function,the real player is "player.player"
↶ Replying to WhiseNT : You used "player" instead of "event" so in this function,the real player is "player.player"
Oh, i forgot to mention that i changed 'event' to 'player' to test, because with 'event' it was not working too :/

WhiseNT 

no any error in logs? I mean the error in the server.log

[View 88e5ea20f89f72cf.png]

Sometimes it loads without errors, sometimes it give some "cannot read property"
Withou errors, but it doesn't work