Solved Autocompressor that works when in offhand

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

jmqr

Member
Jul 31, 2024
3
0
1
24
I tried coding an autocompressor that works in offhand but i get this error:
image.png

this is the code:

Code:
on join:
  if loop-player's offhand tool is hopper minecart named "&6Autocompresser &7[&a1&7]":
    every 1 ticks:
       loop all players:
          if loop-player has 32 oak log:
            remove 32 oak log from loop-player's inventory
            give loop-player shiny oak button named "<##796E6E>&lᴄ<##766C6C>&lᴏ<##736A6A>&lᴍ<##706767>&lᴘ <##6B6363>&lᴡ<##686161>&lᴏ<##655E5E>&lᴏ<##625C5C>&lᴅ"
Skript ver: 2.8.0
 
Last edited:
Wait, where did you get loop-player's offhand tool when you didnt loop anyone in the first place..
 
code_language.skript:
every 1 ticks:
  if player's offhand tool is a hopper minecart:
    if name of player's offhand tool is "&6Autocompresser &7[&a1&7]":
      if player has 32 oak wood named "<##796E6E>&lᴡ<##716868>&lᴏ<##6A6262>&lᴏ<##625C5C>&lᴅ":
        remove 32 oak wood from player's inventory
        give player oak button of mending named "<##796E6E>&lᴄ<##766C6C>&lᴏ<##736A6A>&lᴍ<##706767>&lᴘ <##6B6363>&lᴡ<##686161>&lᴏ<##655E5E>&lᴏ<##625C5C>&lᴅ" with all item flags
 
This skript is extremely laggy, why would you do every 1 tick, if there's some players on the server, it's a guaranteed crash and why would you specify it to have all item flags, if you just leave it alone it will have every item flag, this skript is also probably broken since it's a loop event and you use player instead of loop-player, this would be so much less laggy:


Code:
on break:
    if player's offhand is hopper minecart named "&6Autocompresser &7[&a1&7]":
        if player has 32 oak wood named "<##796E6E>&lᴡ<##716868>&lᴏ<##6A6262>&lᴏ<##625C5C>&lᴅ":
            remove 32 oak wood from player's inventory
            give player oak button of mending named "<##796E6E>&lᴄ<##766C6C>&lᴏ<##736A6A>&lᴍ<##706767>&lᴘ <##6B6363>&lᴡ<##686161>&lᴏ<##655E5E>&lᴏ<##625C5C>&lᴅ"

# If you don't want the mending to show up:
on break:
    if player's offhand is hopper minecart named "&6Autocompresser &7[&a1&7]":
        if player has 32 oak wood named "<##796E6E>&lᴡ<##716868>&lᴏ<##6A6262>&lᴏ<##625C5C>&lᴅ":
            remove 32 oak wood named "<##796E6E>&lᴡ<##716868>&lᴏ<##6A6262>&lᴏ<##625C5C>&lᴅ" from player's inventory
            give player shiny oak button named "<##796E6E>&lᴄ<##766C6C>&lᴏ<##736A6A>&lᴍ<##706767>&lᴘ <##6B6363>&lᴡ<##686161>&lᴏ<##655E5E>&lᴏ<##625C5C>&lᴅ"

I would also recommend using functions since they are way cleaner and cause less lagg.
 
This skript is extremely laggy, why would you do every 1 tick, if there's some players on the server, it's a guaranteed crash and why would you specify it to have all item flags, if you just leave it alone it will have every item flag, this skript is also probably broken since it's a loop event and you use player instead of loop-player, this would be so much less laggy:


Code:
on break:
    if player's offhand is hopper minecart named "&6Autocompresser &7[&a1&7]":
        if player has 32 oak wood named "<##796E6E>&lᴡ<##716868>&lᴏ<##6A6262>&lᴏ<##625C5C>&lᴅ":
            remove 32 oak wood from player's inventory
            give player oak button of mending named "<##796E6E>&lᴄ<##766C6C>&lᴏ<##736A6A>&lᴍ<##706767>&lᴘ <##6B6363>&lᴡ<##686161>&lᴏ<##655E5E>&lᴏ<##625C5C>&lᴅ"

# If you don't want the mending to show up:
on break:
    if player's offhand is hopper minecart named "&6Autocompresser &7[&a1&7]":
        if player has 32 oak wood named "<##796E6E>&lᴡ<##716868>&lᴏ<##6A6262>&lᴏ<##625C5C>&lᴅ":
            remove 32 oak wood named "<##796E6E>&lᴡ<##716868>&lᴏ<##6A6262>&lᴏ<##625C5C>&lᴅ" from player's inventory
            give player shiny oak button named "<##796E6E>&lᴄ<##766C6C>&lᴏ<##736A6A>&lᴍ<##706767>&lᴘ <##6B6363>&lᴡ<##686161>&lᴏ<##655E5E>&lᴏ<##625C5C>&lᴅ"

I would also recommend using functions since they are way cleaner and cause less lagg.
I also attached a skript with the enchant on player's item not showing up, if that's why you wrote with all item flags which should be with all flags hidden instead, but it's better with just adding shiny.