I'm making this skript as part of the animation for the opening of a card pack, it's where the player right clicks the shulker box with the item, it turns into the living entity with the nbt data, and it's SUPPOSED to remove the living shulker right before setting the original shulker box back but for some reason none of the normal things are working. Help would be much appreciated 
on right click:
# make sure it's a red shulker box
if type of clicked block is red shulker box:
# check the player is holding the correct item
if player's tool is brewer pottery sherd:
cancel event # prevent normal shulker box opening
# store block and location
set {_loc} to location of clicked block
set {_original} to type of clicked block
# remove the shulker box
set block at {_loc} to air
# coordinates (lower Y so the shulker fits properly)
set {_x} to x-coordinate of {_loc}
set {_y} to y-coordinate of {_loc} - 1
set {_z} to z-coordinate of {_loc}
# summon the open shulker
execute console command "summon minecraft:shulker %{_x}% %{_y}% %{_z}% {Color:14,Peek:100,NoAI:1b}"
# tag it 1 tick later
wait 1 tick
execute console command "tag @e[type=minecraft:shulker,sort=nearest,limit=1,distance=..2] add temp_shulker"
send "&cOpening red shulker..." to player
set {_shulker} to last spawned entity
# wait, then remove shulker first
wait 5 seconds
kill {_shulker}
wait 5 ticks
# only restore the block after the shulker is gone
set block at {_loc} to {_original}
send "&aShulker removed and original block restored." to player
on right click:
# make sure it's a red shulker box
if type of clicked block is red shulker box:
# check the player is holding the correct item
if player's tool is brewer pottery sherd:
cancel event # prevent normal shulker box opening
# store block and location
set {_loc} to location of clicked block
set {_original} to type of clicked block
# remove the shulker box
set block at {_loc} to air
# coordinates (lower Y so the shulker fits properly)
set {_x} to x-coordinate of {_loc}
set {_y} to y-coordinate of {_loc} - 1
set {_z} to z-coordinate of {_loc}
# summon the open shulker
execute console command "summon minecraft:shulker %{_x}% %{_y}% %{_z}% {Color:14,Peek:100,NoAI:1b}"
# tag it 1 tick later
wait 1 tick
execute console command "tag @e[type=minecraft:shulker,sort=nearest,limit=1,distance=..2] add temp_shulker"
send "&cOpening red shulker..." to player
set {_shulker} to last spawned entity
# wait, then remove shulker first
wait 5 seconds
kill {_shulker}
wait 5 ticks
# only restore the block after the shulker is gone
set block at {_loc} to {_original}
send "&aShulker removed and original block restored." to player