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
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
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.
4 comments
Yes, as long as both of those conditions are true the script will run.
So my scripts not working because of the "AtBottom == false". That value needs to be equal to true to run?
yep
If you want it to run if either are true, you can use the keyword "or" instead.