1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Loop Players Issue

Discussion in 'Skript' started by Turb032, Jun 28, 2020.

  1. Turb032

    Turb032 Well-Known Member

    Joined:
    Jan 16, 2020
    Messages:
    76
    Likes Received:
    0
    Hi guys, i've been searching for a long time a way to loop all players at the same time and creating a bossbar. The problem is that the bossbar does not show for all the players, but for only ONE player. Here is my code:
    Code (Text):
    1.  
    2. every 1 tick:
    3.     loop all players:
    4.         create bossbar titled "&a&lLevel &7&l[&6&l%{level.%loop-player%}%&7&l] &7&l[&b%{exp.%loop-player%}%&7&l]" and id "level" for loop-player with progress {exp.%loop-player%} with colors blue
    5.         if {exp.%loop-player%} is greater than or equal to 100:
    6.             set {exp.%loop-player%} to 0
    7.             add 1 to {level.%loop-player%}
    8.             send loop-player title "&a&lLevel Up!" with subtitle "&7&m&l---------------" for 2 seconds
    9.             play sound "entity.player.levelup" with volume 1 at loop-player
    10.             stop
    11.  
     
    #1 Turb032, Jun 29, 2020
    Last edited: Jun 29, 2020
  2. Dave

    Dave Well-Known Member

    Joined:
    Jul 20, 2018
    Messages:
    218
    Likes Received:
    7
    try this (?)
    Code (Text):
    1.  and id "level.%loop-player%"
    and also DON'T use every 1 tick, no one would recommend u to use that shit, this will decrease ur server performance

    example: if you have 40 players online and "every x (tick | second)" with "loop all players", the server will loop players 800 times in 1 second = 20 ticks, 1 tick = 50 ms

    Code (Text):
    1. on join:
    2.     while player is online:
    3.         #do stuff
    4.         wait 1 second
     
    #2 Dave, Jun 30, 2020
    Last edited: Jun 30, 2020
  3. Turb032

    Turb032 Well-Known Member

    Joined:
    Jan 16, 2020
    Messages:
    76
    Likes Received:
    0
    Ok, now i have this:
    Code (Text):
    1. on join:
    2.     while player is online:
    3.         create bossbar titled "&6&lLevel &f[&6&l%{level.%player%}%&f]   &bExp &f[&b%{exp.%player%}%&f]" and id "level.%player%" for player with progress {exp.%player%} with colors blue
    4.         if {exp.%player%} is greater than or equal to 100:
    5.             set {exp.%player%} to 0
    6.             add 1 to {level.%player%}
    7.             send player title "&a&lLevel Up!" with subtitle "&7&m&l---------------" for 2 seconds
    8.             play sound "entity.player.levelup" with volume 1 at player
    9.             wait 1 second
    But now when i join the server, it shows me 1 Bossbar and often 2 glitched bossbars, also, when i join, the server does not load chunks and than it crashes.. Any idea?
     
  4. Dave

    Dave Well-Known Member

    Joined:
    Jul 20, 2018
    Messages:
    218
    Likes Received:
    7
    https://gyazo.com/8ad70cfeb83be50ec387279e91ad97a9
    correct wait
    Code (Text):
    1. on join:
    2.     wait 1 second
    3.     while player is online:
    4.         create bossbar titled "&6&lLevel &f[&6&l%{level.%player%}%&f]   &bExp &f[&b%{exp.%player%}%&f]" and id "level.%player%" for player with progress {exp.%player%} with colors blue
    5.         if {exp.%player%} is greater than or equal to 100:
    6.             set {exp.%player%} to 0
    7.             add 1 to {level.%player%}
    8.             send player title "&a&lLevel Up!" with subtitle "&7&m&l---------------" for 2 seconds
    9.             play sound "entity.player.levelup" with volume 1 at player
    10.         wait 1 second
    thats why the server is creating bossbars without waiting
     
  5. egamer3000

    egamer3000 Active Member

    Joined:
    Nov 25, 2019
    Messages:
    34
    Likes Received:
    6
    DO NOT use while player is online..
    this means, until the player leaves, every single second, this code was ran 20 times.
     
  6. Dave

    Dave Well-Known Member

    Joined:
    Jul 20, 2018
    Messages:
    218
    Likes Received:
    7
    this is WAY better than EVERY 1 TICK, the server can do this without problem and read above what I said
     
    #6 Dave, Jul 2, 2020
    Last edited: Jul 2, 2020
  7. Turb032

    Turb032 Well-Known Member

    Joined:
    Jan 16, 2020
    Messages:
    76
    Likes Received:
    0
    Code (Text):
    1. on join:
    2.     wait 5 seconds
    3.     while player is online:
    4.         create bossbar titled "&6&lLevel &f[&6&l%{level.%player%}%&f]   &bExp &f[&b%{exp.%player%}%&7 | &b%{maxexp.%player%}%&f]" and id "level.%player%" for player with progress {exp.%player%} with colors blue  
    5.         if {exp.%player%} is greater than or equal to {maxexp.%player%}:
    6.             set {exp.%player%} to 0
    7.             add 1 to {level.%player%}
    8.             send player title "&a&lLevel Up!" with subtitle "&7&m&l---------------" for 2 seconds
    9.             play sound "entity.player.levelup" with volume 1 at player
    10.             add 50 to {maxexp.%player%}
    11.             wait 5 seconds
    12.            
    Aww... It still crashing the server, i just put wait 5 seconds instead of 1, but nothing, every time it crashes. With "every 1 tick" it works well, why shouldn't i do it?
    --- Double Post Merged, Jul 2, 2020, Original Post Date: Jul 2, 2020 ---
    OOH wait, i just noticed that i put the second "wait seconds" in the wrong place.. It works well but, will it decrese server's performance or something?
     
  8. Detective Vapor

    Joined:
    Jul 2, 2020
    Messages:
    15
    Likes Received:
    0
    @Turb032 You need to put the "wait 1 second" after "while player is online:" so that it doesn't lag. A while loop that keeps doing it over and over again without any timing will crash your server.
     
  9. Dave

    Dave Well-Known Member

    Joined:
    Jul 20, 2018
    Messages:
    218
    Likes Received:
    7
    you just need a good vps and will works without problems
     
  10. Turb032

    Turb032 Well-Known Member

    Joined:
    Jan 16, 2020
    Messages:
    76
    Likes Received:
    0
    is 16gb of RAM enough? I don't know very well about vps and stuff, sooo yeah..
     
  11. Dave

    Dave Well-Known Member

    Joined:
    Jul 20, 2018
    Messages:
    218
    Likes Received:
    7
    ye it is!
     
  12. Turb032

    Turb032 Well-Known Member

    Joined:
    Jan 16, 2020
    Messages:
    76
    Likes Received:
    0
    Ok perfect xD
    --- Double Post Merged, Jul 2, 2020, Original Post Date: Jul 2, 2020 ---
    Thank you all for helping me with that skript!
     
  13. Dave

    Dave Well-Known Member

    Joined:
    Jul 20, 2018
    Messages:
    218
    Likes Received:
    7
    you're welcome
     
Loading...