Works fine for me.
command backpack <text=small> <player=%player%>:
permission: admin.bp
permission message: &cInsufficient permissions!
usage: &c/backpack <small/medium/large> [player]
trigger:
if arg-1 isn't "small", "medium" or "large":
send "&c/backpack <small/medium/large> [player]"
stop
give arg-2 1st element of (chest named "&fSmall Backpack", chest named "&fMedium Backpack" and chest named "&fLarge Backpack" where [name of input in lowercase contains arg-1]) with lore "%(size of {backpack::%player's uuid%::*} ? 0) + 1%" and player's uuid
send "&aGave you a %arg-1 in lowercase% &abackpack!"
on place of chest:
cancel event if player's tool's name ends with " Backpack"
on right click holding chest:
stop if player's tool's name doesn't end with " Backpack"
stop if line 2 of player's tool's lore isn't player's uuid
cancel event
set metadata value "bp" of player to line 1 of player's tool's lore
set {_size} to (1 if player's tool's name starts with "&fSmall ", else 3) if player's tool's name doesn't start with "&fLarge "
set {_} to chest inventory with ({_size} ? 6) rows named player's tool's name
loop {backpack::%player's uuid%::%line 1 of player's tool's lore%::*}:
set slot loop-index parsed as int of {_} to loop-value
open {_} to player
on inventory close:
stop if metadata value "bp" of player isn't set
set {_} to metadata value "bp" of player
set {backpack::%player's uuid%::%{_}%::*} to all items in event-inventory
delete metadata value "bp" of player