Failing to get specific player data
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);
}
});
persistantData is only data you set yourself through kubejs.
You're looking for nbt, so just replace the
... .persistantData ...
with ... .nbt ...
.Thanks! I'll try it
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: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
}
});
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
}
});
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…
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 :/
Sometimes it loads without errors, sometimes it give some "cannot read property"
Withou errors, but it doesn't work