Hello! I'm still new to script and learning as I go. After some trial and error i found out that chaining if statements is kinda unreliable, so I figured out how to use loop instead, but I worry it will run my script excessively and cause lag when the server is full of players. Please help me figure out how to optimize this code so it will only run when the player is wearing a particular item (the loop is to ensure the item breaks because for some reason if I use script to reduce durability it won't actually break the item.)
Code:
on player step:
lore of player's boots contains "&eto gain experience while you walk!":
give 1 xp to the player
on player level up:
lore of player's boots contains "&eto gain experience while you walk!":
damage boots of player by 1
on player step:
loop items in player's inventory:
if durability of player's boots is 0:
delete player's boots
play sound "entity.item.break" with volume 0.8