Problem with my Loop

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

Quentin_GHG

New Member
Mar 15, 2024
9
0
1
23
Hello I wanted to code A helmet that Activates on wearing it and Entering a command did all that, and Now the loop keeps crashing my Server, Im pretty new to skript so I dont reallly know how to use loops perhaps someone could explain it to me or just help me directly by coding it that way, would be awesome Help, thanks in advance ;D

command /toggleminer:
trigger:
if {minerhelmet%player%} is not set:
set {minerhelmet%player%} to true
if {minerhelmet%player%} is true:
set {minerhelmet%player%} to false
send message "&b&l-Auralis- &fMiners Helmet &coff" to player
set block at {minerslight%player%} to air
stop
if {minerhelmet%player%} is false:
send message "&b&l-Auralis- &fMiners Helmet &aon" to player
set {minerhelmet%player%} to true
loop 1000000 times:
if player is wearing a carved pumpkin with custom model data 7:
if {minerhelmet%player%} is true:
if {minerslight%player%} is 0:
block at player is air:
set {minerslight%player%} to position of player
set block at {minerslight%player%} to light block
wait 20 ticks
set block at {minerslight%player%} to air
set {minerslight%player%} to 0

on quit:
set {minerslight%player%} to 0
set block at {minerslight%player%} to air
 

Attachments

  • miner_helmet.sk
    1.2 KB · Views: 31
tbh i have no idea what do you want/need, you have that command and you are looping 1 million times something :emoji_skull: Just describe what you need from the helmet to do after you equip and unequip it and ill try to do it.
 
He wants a helmet that makes a light at you, and then deletes it, in which case I recommend using a periodic event rather than looping a million times.

Something like
Code:
every 1 second:
    #stuff
  
#or

on join:
    while player is online:
        #stuff
        wait 1 second

Please don't simply make the code for him @DanRub, allow him to figure out the best way to work it. I can say I recommend not using a command or a toggle and instead just checking the name of the player's helmet. For example,
Code:
on join:
    while player is online:
        name of player's helmet contains "name of helmet or whatever":
            #do stuff with light blocks
            
        wait 1 second
 
Okay thanks for the help of you all, the plan with on join: was way better and it works perfetly fine, :emoji_grinning: thamks for helping, it made my day so much better and my skript, thank you both
 
Last edited:
I understand. It seems to be because once its toggled off, its still looping, not only that but it starts ANOTHER loop. so you have 2 loops, each 1 million times, and theres no delay between them firing because theres no delay if the helmet is off.
 
If you really want to put it in a command, do this
Python:
command toggleminer:
    permission: miner.toggle
    trigger:
        {minerhelm::%player's uuid%} is not true:
            set {minerhelm::%player's uuid%} to true
            send message "&b&l-Auralis- &fMiners Helmet &aon" to player
        else:
            set {minerhelm::%player's uuid%} to false
            send message "&b&l-Auralis- &fMiners Helmet &coff" to player
          
on join:
    while player is online:
        {minerhelm::%player's uuid%} = true:
            #do stuff
          
          
          
          
        wait 1 second

But thats all I can really suggest.
If while player is online didnt work, which is weird, you can try using every 1 second