So I have this server script (kill_count.js) that adds an nbt tag to an item, which is elsewhere called for a tooltip on the item. The issue is that due to the way it is set up, it is null before you kill an entity with it, which has been causing some crashes. I was trying to set up a startup script to give the sword the nbt tag and set it to 0 before even loading the world, but that doesn't seem to work.
#How to initialize an NBT tag?
54 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
Paste version of kill_count.js from @bright narwhal
how did you inplemented the client script? And what's the crash log?
event.addAdvanced('simplyswords:slumbering_lichblade', (item, advanced, text)=>{
const killCount = item.nbt.get('killCount')
text.add(
Text.of(killCount)
.append(Text.of('/50'))
)
})
});```
I added "if(killCount == null) {killCount = 0}" before the text add but it still says null/50 in the tooltip 
Paste version of message.txt from @bright narwhal
It now crashes immediately whenever I hold the sword
try this
ItemEvents.tooltip(event => {
event.addAdvanced('simplyswords:slumbering_lichblade', (item, advanced, text)=>{
const killCount = item.nbt? (item.nbt.get('killCount') || 0) : 0
text.add(
Text.of(killCount)
.append(Text.of('/50'))
)
})
});
It still crashes the second I put the item in my hand. The tooltip reads 0 in the creative menu though
send the latest log again
I wonder if it's the client scripts that caused the crash
I think so, it doesn't crash otherwise
Paste version of message.txt from @bright narwhal
does removing the entire client script stop the crash?
send the entire client script then
Wait no I lied
It still crashes when I remove that
But it was working before...
Its in the original post
Do you have any other scripts related to the swords?
Just this
Paste version of unbreakable_weapons.js from @bright narwhal
why do you set it to 0?
It seemed to function to make it unbreakable
Is that not expected?
Ope no the crash was from the damage modification script I made based on your example script
I made a dumb error
what error?
Paste version of damage_modification.js from @bright narwhal
I thought it would but then the 5 and 2 are just getting added to the original attack damage, I can't seem to set it lower
oh, btw, the remove part syntax is not correct
Can't do Ingredient.of for an array? Or what
attributes.remove(Ingredient.of(['simplyswords:slumbering_lichblade', 'simplyswords:waking_lichblade']), 'minecraft:generic.attack_damage')
you need to put the array into Ingredient.of(...)
The [] cannot replace ()
And I just tested it, setting the maxDamage to 0 or -1 can cause the item to become unenchantable.
If you don't want that to happen, another method to make it unbreakable is to add this in server script
ItemEvents.firstLeftClicked("minecraft:diamond_sword", event => { //replace the "minecraft:diamond_sword" with the swords you want
event.item.setDamageValue(0)
})
Huh, really?
In this case it is working for me to enchant it, at least with sharpness
anvil enchantment would work, but enchant table would not