Solved Cancel Teleportation On Move

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

DeoviserYT

Member
Aug 4, 2024
4
0
1
37
Hi! I'm trying to make a script on my server so when you do /hub or /lobby it counts down from 3, but if you move the teleportation is canceled. When I try it then it works fine but you still get teleported if you move.
My code is:
Code:
command /lobby:
  aliases: /hub
  trigger:
    if {_hub::%player%} is not true:
      set {_hub::%player%} to true
      send "&8&l[&c&lEmpy&e&lrean&8&l] &aTeleporting to lobby! Don't move!"
      while {_hub::%player%} is true:
        execute command "/title %player% actionbar {""text"":""Teleporting in 3"",""color"":""aqua"",""bold"":true}"
        wait 1 second
        execute command "/title %player% actionbar {""text"":""Teleporting in 2"",""color"":""aqua"",""bold"":true}"
        wait 1 second
        execute command "/title %player% actionbar {""text"":""Teleporting in 1"",""color"":""aqua"",""bold"":true}"
        wait 1 second
        execute command "/title %player% actionbar {""text"":""Teleported!"",""color"":""aqua"",""bold"":true}"
        execute command "/mvtp %player% world"
        set {_hub::%player%} to false
    else:
      send "&8&l[&c&lEmpy&e&lrean&8&l] &cYou are already teleporting!" to player

on player move:
  if {_hub::%player%} is true:
    clear {_hub::%player%}
    wait 1 tick
    execute command "/title %player% actionbar {""text"":""Teleportation Canceled!"",""color"":""red"",""bold"":true}"
    send "&8&l[&c&lEmpy&e&lrean&8&l] &cTeleportation canceled because you moved!" to player
Please help!

EDIT: Just don't mind that I used clear instead of setting it to false, I do that sometimes
 
You could do something like this:

Code:
set {_hubtimer.%player%} to 3
      while {_hub::%player%} is true:
        execute command "/title %player% actionbar {""text"":""Teleporting in %{_hubtimer.%player%}%"",""color"":""aqua"",""bold"":true}"
        wait 1 second
        set {_hubtimer.%player%} to {_hubtimer.%player%} - 1
        if {_hubtimer.%player%} is 0:
            set {_hub::%player%} to false
    execute command "/mvtp %player% world"

Your code isnt working because Skript doesn't care if you've made the while statement false if the while statement is already running; it only checks while statement conditions when hitting the condition again.
 
You could do something like this:

Code:
set {_hubtimer.%player%} to 3
      while {_hub::%player%} is true:
        execute command "/title %player% actionbar {""text"":""Teleporting in %{_hubtimer.%player%}%"",""color"":""aqua"",""bold"":true}"
        wait 1 second
        set {_hubtimer.%player%} to {_hubtimer.%player%} - 1
        if {_hubtimer.%player%} is 0:
            set {_hub::%player%} to false
    execute command "/mvtp %player% world"

Your code isnt working because Skript doesn't care if you've made the while statement false if the while statement is already running; it only checks while statement conditions when hitting the condition again.
but if he doesnt add a wait wouldnt that crash his server when the condition is met? im pretty sure while statements needs a wait
 
Isn't there a wait? Right under execute command, and there is an exit for the loop with if {_hubtimer.%player%} is 0: if that's what you mean.
 
Hi! I'm trying to make a script on my server so when you do /hub or /lobby it counts down from 3, but if you move the teleportation is canceled. When I try it then it works fine but you still get teleported if you move.
My code is:
Code:
command /lobby:
  aliases: /hub
  trigger:
    if {_hub::%player%} is not true:
      set {_hub::%player%} to true
      send "&8&l[&c&lEmpy&e&lrean&8&l] &aTeleporting to lobby! Don't move!"
      while {_hub::%player%} is true:
        execute command "/title %player% actionbar {""text"":""Teleporting in 3"",""color"":""aqua"",""bold"":true}"
        wait 1 second
        execute command "/title %player% actionbar {""text"":""Teleporting in 2"",""color"":""aqua"",""bold"":true}"
        wait 1 second
        execute command "/title %player% actionbar {""text"":""Teleporting in 1"",""color"":""aqua"",""bold"":true}"
        wait 1 second
        execute command "/title %player% actionbar {""text"":""Teleported!"",""color"":""aqua"",""bold"":true}"
        execute command "/mvtp %player% world"
        set {_hub::%player%} to false
    else:
      send "&8&l[&c&lEmpy&e&lrean&8&l] &cYou are already teleporting!" to player

on player move:
  if {_hub::%player%} is true:
    clear {_hub::%player%}
    wait 1 tick
    execute command "/title %player% actionbar {""text"":""Teleportation Canceled!"",""color"":""red"",""bold"":true}"
    send "&8&l[&c&lEmpy&e&lrean&8&l] &cTeleportation canceled because you moved!" to player
Please help!

EDIT: Just don't mind that I used clear instead of setting it to false, I do that sometimes
its not working because the var {_hub::%player%} is a local var and it gets deleted right after the command is over, and you dont need to execute that command theres an effect for that
 
its not working because the var {_hub::%player%} is a local var and it gets deleted right after the command is over, and you dont need to execute that command theres an effect for that and btw mb didnt saw that wait
 
its not working because the var {_hub::%player%} is a local var and it gets deleted right after the command is over, and you dont need to execute that command theres an effect for that
When I tried it did cancel it but the timer kept going and I did teleport.
 
Never mind! I made some new code and it worked, it looks like this

Code:
command /lobby:
  aliases: /hub
  trigger:
    if {hub::%player%} is not true:
      set {hub::%player%} to true
      send "&8&l[&c&lEmpy&e&lrean&8&l] &aTeleporting to lobby! Don't move!"
      execute command "/title %player% actionbar {""text"":""Teleporting in 3"",""color"":""aqua"",""bold"":true}"
      wait 1 second
      if {hub::%player%} is true:
        execute command "/title %player% actionbar {""text"":""Teleporting in 2"",""color"":""aqua"",""bold"":true}"
        wait 1 second
        if {hub::%player%} is true:
          execute command "/title %player% actionbar {""text"":""Teleporting in 1"",""color"":""aqua"",""bold"":true}"
          wait 1 second
          if {hub::%player%} is true:
            execute command "/title %player% actionbar {""text"":""Teleported!"",""color"":""aqua"",""bold"":true}"
            execute command "/mvtp %player% world"
            set {hub::%player%} to false
          else:
            execute command "/title %player% actionbar {""text"":""Teleportation Canceled!"",""color"":""red"",""bold"":true}"
            send "&8&l[&c&lEmpy&e&lrean&8&l] &cTeleportation canceled because you moved!" to player
        else:
          execute command "/title %player% actionbar {""text"":""Teleportation Canceled!"",""color"":""red"",""bold"":true}"
          send "&8&l[&c&lEmpy&e&lrean&8&l] &cTeleportation canceled because you moved!" to player
      else:
        execute command "/title %player% actionbar {""text"":""Teleportation Canceled!"",""color"":""red"",""bold"":true}"
        send "&8&l[&c&lEmpy&e&lrean&8&l] &cTeleportation canceled because you moved!" to player
    else:
      send "&8&l[&c&lEmpy&e&lrean&8&l] &cYou are already teleporting!" to player

on player move:
  if {hub::%player%} is true:
    clear {hub::%player%}