Simple Script not working as intended.

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

Status
Not open for further replies.

KingDingers

Member
Nov 6, 2019
1
0
0
27
Skript Version: Skript v2.4 - beta 9
Minecraft Version: 1.14.4
Addons: Skellet


Code:
on player held item change:

    if held item of player is carrot on a stick:
        apply mining fatigue 10 to player for 9999 days
        apply haste 5 to player for 9999 days
    while held item of player is carrot on a stick:
        wait 1 tick
    remove mining fatigue from player
    remove haste from player

Hello, I just started using Skript a few hours ago and was working on a (simple?) skript and have hit a wall.
I looked through just about everything I think, and I'm pretty sure I have narrowed down my problem but do not know how to solve it.

The skript works as intended kinda, but if I have back to back carrot on a sticks on my hotbar it will remove the potion effects, until I swap back to the other one. Also noticed on pickup it will not apply a potion effect either. Not entirely sure how to go about fixing it. If anyone could help me out it would be appreciated!!

I have also tried this and it worked better, but it made items that were not a carrot on a stick move up and down (assuming because it was constantly trying to remove a non existent potion effect?).

Code:
every second:
    loop all players:
        if loop-player is holding a carrot on a stick:
            set {holding_carrot::%loop-player%} to true
            apply mining fatigue 10 to loop-player
            apply haste 5 to loop-player
        else:
            set {holding_carrot::%loop-player%} to false
            remove haste from loop-player
            remove mining fatigue from loop-player
        while {holding_carrot::%loop-player%} is true:
            wait 1 tick


(Sorry if the fix is obvious just starting out)
 
looks like the loop is most reliable, but don't use while in that, it breaks everything, use it like this:
Code:
every second:
    loop all players:
        if loop-player is holding a carrot on a stick:
            {holding_carrot::%loop-player%} is not set:
               set {holding_carrot::%loop-player%} to true
           apply mining fatigue 10 to loop-player
            apply haste 5 to loop-player
        else if {holding_carrot::%loop-player%} is set:
           delete {holding_carrot::%loop-player%}
            loop-player has haste:
               remove haste from loop-player
            loop-player has mining fatigue:
               remove mining fatigue from loop-player
(I have made it delete the variable instead of set to false, since that prevents memory leaks)
 
Status
Not open for further replies.