Solved "cancel event" not working

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Captain_Dog_

Member
Jul 19, 2023
2
0
1
24
This is my current code, in which for whatever reason the "cancel event" that should cancel inventory click isn't working. Am I missing something or is this a bug within skript?

Code:
function makeMenu(name: text, rows: number) :: inventory:
    set {_gui} to a new chest inventory with {_rows} rows with name {_name}
    set slot 1 of {_gui} to iron axe named "&1Pirate" with lore "&r&fWays to gain xp:%nl%&r&fKilling players%nl%&r&flooting (use /loot)%nl%&r&fswimming"
    set slot 2 of {_gui} to diamond pickaxe named "&fMiner" with lore "&r&fWays to gain xp:%nl%&r&fMining"
    set slot 3 of {_gui} to spyglass named "&6Adventurer" with lore "&r&fWays to gain xp:%nl%&r&fWalking"
    set slot 4 of {_gui} to gold sword named "&8Warrior" with lore "&r&fWays to gain xp:%nl%&r&fKilling Monsters"
    set slot 5 of {_gui} to carrot named "&aFarmer" with lore "&r&fWays to gain xp:%nl%&r&fHarvesting grown crops"
    set slot 6 of {_gui} to oak log named "&6Builder" with lore "&r&fWays to gain xp:%nl%&r&fPlacing blocks"
    return {_gui}

command /class choose:
    trigger:
        if {clss::%player%} is not set:
            set {_menu} to makeMenu("Classes", 1)
            open {_menu} to player
            add {_menu} to {my inventories::*}
        else if {clss::%player%} is "no class":
            set {_menu} to makeMenu("Classes", 1)
            add {_menu} to {my inventories::*} # Prepare to listen to this inventory.
            open {_menu} to player
        else:
            send "&l&3[CaribbeanFun]&r: &4You have already chosen a class"

on inventory click: # Listen for players clicking in any inventory.
    if {my inventories::*} contains event-inventory:
        cancel event
        index of event-slot is 1:
            set {clss::%player%} to "Pirate"
            send "&l&3[CaribbeanFun]&r: You have chosen %{clss::%player%}%"
            close inventory of player
        index of event-slot is 2:
            set {clss::%player%} to "Miner"
            send "&l&3[CaribbeanFun]&r: You have chosen %{clss::%player%}%"
            close inventory of player
        index of event-slot is 3:
            set {clss::%player%} to "Adventurer"
            send "&l&3[CaribbeanFun]&r: You have chosen %{clss::%player%}%"
            close inventory of player
        index of event-slot is 4:
            set {clss::%player%} to "Warrior"
            send "&l&3[CaribbeanFun]&r: You have chosen %{clss::%player%}%"
            close inventory of player
        index of event-slot is 5:
            set {clss::%player%} to "Farmer"
            send "&l&3[CaribbeanFun]&r: You have chosen %{clss::%player%}%"
            close inventory of player
        index of event-slot is 6:
            set {clss::%player%} to "Builder"
            send "&l&3[CaribbeanFun]&r: You have chosen %{clss::%player%}%"
            close inventory of player

on inventory close: # No longer need to listen to this inventory.
    {my inventories::*} contains event-inventory:
        remove event-inventory from {my inventories::*}
 
The solution ended up being restarting the server multiple times. Skript was trying to update but kept cancelling half way through. It randomly just worked after multiple restarts/