Explanation
The Player method "addExperience" only removes the player's XP until the level cap is reached. For example, if a player is at XP level 5 and calls the method: :addExperience(-500) It will not change the player's level, instead they will be at level 5 with no extra XP.
It should also be noted that unlike negative parameters, using positive parameters can increment the player's level. This test is also done using the 1.15-beta scripting version.
Steps to Replicate
Download the add-on
Open Minecraft Preview 1.21.20.24
Create a world using this add-on
Use command: "give @s sky:skulk_battery"
Use the item, which uses a custom component, to run the following line that will increase or decrease XP based on a 50% percent chance.
Math.random() < 0.5 ? arg.source.addExperience(1000) : arg.source.addExperience(-1000);
Notice how the XP level never decreases for the player.
Attachments
Comments 3

Trying to load the addon in 1.21.30.21 and it's erroring and showing that it's got an invalid pack ID, verson, name and description.
Hi, we could not reproduce that issue on Preview 1.21.60.21. When using the "Skulk Battery" item, exp was neither added nor taken away. Can you attach a video showing the steps to reproduce the issue? Also, do any of the experiments need to be enabled for the package to function?
This issue is being temporarily resolved as Awaiting Response. Once the requested information has been delivered, the report will be reopened automatically.
Quick Links:
📓 Bug Tracker Guidelines – 📧 Mojang Support (Technical Issues) – 📧 Microsoft Support (Account Issues)
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki