Check if player clicks item

  • 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 community!

    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!

LeeifMR

Member
Oct 2, 2024
27
1
3
I am trying to make a skript that does stuff when you click an item. But nothing is happening when I click the item?

Code:
on right click on a villager:
    if name of clicked entity is "Oak Shop":
        cancel event
        open chest with 3 rows named "&8Oak Shop" to player
        wait 1 tick
        loop 30 times:
            format slot loop-number of player with gray stained glass pane named " " to be unstealable
        format slot 0 of player with gray stained glass pane named " " to be unstealable
        format slot 11 of player with leather chestplate named "&eOak Gear" to be unstealable
        format slot 13 of player with wooden axe named "&eOak Axes" to be unstealable
        format slot 15 of player with an anvil named "&eCompressor" to be unstealable
        
on inventory click:
    if inventory name of player's inventory is "&8Oak Shop":
        cancel event
        if event-slot is a leather chestplate:
            close player's inventory
            make player execute command "/shopkeeper open Real-Oak"
        if event-slot is a wooden axe:
            close player's inventory
            make player execute command "/shopkeeper open Real-Oak2"
        if event-slot is an anvil:
            close player's inventory
            make player execute command "/shopkeeper open Real-Oak3"
 
Try event-item rather than event-slot

Code:
on inventory click:
    inventory name of player's inventory is "&8Oak Shop"
    cancel event
    if event-item is a leather chestplate:
        close player's inventory
        make player execute command "/shopkeeper open Real-Oak"
    else if event-item is a wooden axe:
        close player's inventory
        make player execute command "/shopkeeper open Real-Oak2"
    else if event-item is an anvil:
        close player's inventory
        make player execute command "/shopkeeper open Real-Oak3"

Also try to minimize nesting
 
Try event-item rather than event-slot

Code:
on inventory click:
    inventory name of player's inventory is "&8Oak Shop"
    cancel event
    if event-item is a leather chestplate:
        close player's inventory
        make player execute command "/shopkeeper open Real-Oak"
    else if event-item is a wooden axe:
        close player's inventory
        make player execute command "/shopkeeper open Real-Oak2"
    else if event-item is an anvil:
        close player's inventory
        make player execute command "/shopkeeper open Real-Oak3"

Also try to minimize nesting
Thanks