Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

4 comments

0

Yes, as long as both of those conditions are true the script will run.

0

So my scripts not working because of the "AtBottom == false". That value needs to be equal to true to run?

0

yep

0

If you want it to run if either are true, you can use the keyword "or" instead.

2 answers

✓ Accepted answer

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.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.