Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you have more than one condition in a while true do loop?

Asked by 6 years ago

Can you have more than one condition in a while true do loop?

while PrimaryPart.Position ~= desiredposition and AtBottom == false do
--[[
My 
code
Is
Here
--]]
end
0
Yes, as long as both of those conditions are true the script will run. dirk2999 103 — 6y
0
So my scripts not working because of the "AtBottom == false". That value needs to be equal to true to run? Lost_Phantom 4 — 6y
0
yep CjayPlyz 643 — 6y
0
If you want it to run if either are true, you can use the keyword "or" instead. amanda 1059 — 6y

2 answers

Log in to vote
0
Answered by
amanda 1059 Moderation Voter
6 years ago
Edited 6 years ago

Yes you can.

You can have any number of expressions separated by and and or. Another way of accomplishing this is by your expression being a function call.

Using a function can help organize code, so that you do not have to do a lot of checks inline.

Here is an example.

local counter = 0

local function iterate()
    counter = counter + 1
    return counter <= 10
end

while iterate() do
    print(counter)
end

It the loop cycles until the function call returns false.

Ad
Log in to vote
0
Answered by
Launderer 343 Moderation Voter
6 years ago

Yes you can sir! For example you could do

while Player.Character.Humanoid.Health > 0 and Player.Character.Humanoid.WalkSpeed > 0 do
print(Player.Name .. " is alive and healthy."
wait()
end

This same thing also works with if and for statements

if Player.Character.Humanoid.Health > 0 and Player.Character.Humanoid.WalkSpeed > 0 then
print(Player.Name .. " is alive and healthy."
end

Answer this question