I have a question. So you know how while true do loops always go on forever? What happens after you break the loop? Does the loop start again once the right conditions are met?
For example,
local plr = game.Players.LocalPlayer local char = plr.Character local torso = char.Torso while char.Torso.Position.Y > 0 do print("Above 0 studs") wait() else if char.Torso.Position.Y <= 0 then break end end
In this script, once the player is below 0 studs in terms of the Y-axis, the loop should break. But will the loop repeat and go again while the player is above 0 studs?
Edit: You are using a while statement incorrectly the while statement does not have an else available for it: http://www.lua.org/pil/4.3.2.html
The while statement will continue until the argument given is false, so essentially the code AFTER the while loop is the else (no else statement needed)
The break command in lua will end a loop and continue to the following code after the loop. Example from roblox wiki are:
while wait() do print("Hi mom!") break -- This forces the endless loop to end end
and
for i = 1, 1000000000 do print("Hi mom!") wait() break -- This forces the ridiculously long loop to end end
"Both of these loops only run once because of the break command, and print “Hi mom!” once."
cited from: https://developer.roblox.com/articles/Roblox-Coding-Basics-Loops#Break
P.S you don't need to have the second if statement inside of your else you can just put:
local plr = game.Players.LocalPlayer local char = plr.Character local torso = char.Torso while char.Torso.Position.Y > 0 do print("Above 0 studs") wait() else break end
Hope this helps!