#I've been gone for a while.
Before I left, everyone openly used wait() as a condition. It was never considered bad and was actually seen as a nice way to omit a single line of code very simply. When I came back, I've been seeing a lot more people contest the idea of using wait() as a condition. Most notably, in while true do loops. Why would that be?
while wait(5) do
print("I waited ~5 seconds")
end
--Does the same thing ^
while true do
wait(5)
print("I waited ~5 seconds")
end
###Hack(v.) - to write or refine computer programs or code
Most people argue that doing this is a "hack" with negative connotation. All coding in ROBLOX is considered a hack by definition. Perhaps people are afraid that one day ROBLOX will "patch" this "hack" and all scripts using wait() as a condition will eventually be broken and all games using it will lag!!! But that is simply not the case either. The reason using wait() as a condition works is because things looking for conditions like if then statements and while loops only check if the statement is "truthy" meaning not false or nil. Wait() returns the time it took (in seconds) to finish yielding the rest of the script. You can test that it returns a number:
print(type(wait(3)))
number
#So my question is this:
Why do some people refuse to use wait, a number, as a condition? There's a group of people against it, but at the same time, those people would be perfectly fine with a script like this:
local array = {23, nil, 42}
if array[1] then
print("Exists")
end
but they are against using a number as a condition like so:
while wait(5) do
print("5 seconds have passed")
end
Is it because wait() yields? Probably not, as most of these people would probably accept this:
script.Parent.Touched:Connect(function(part)
if part.Parent:WaitForChild("Humanoid") then
print("Humanoid exists")
end
end) --WaitForChild was used. It will yield if humanoid does not exist
#Fun fact
You can define a variable with Wait() and it will still delay your script. The only difference is your variable is now a number.
while true do
local a = wait(5)
print(math.floor(a+20))
end
You can use the fact that the variable is a number in pretty cool ways!
local lighting = game:GetService("Lighting")
local DayStarts = 6*60 --Time of day the game starts at from midnight
while true do
local OneMinute = wait(0.25) --1 "ROBLOX minute" is how many irl seconds?
DayStarts = DayStarts+OneMinute/0.25
lighting:SetMinutesAfterMidnight(DayStarts)
end
Wait() returns 2 variables. I am unsure what the second variable means, that could be a bonus question. My theory is it returns the amount of seconds from 5 pm local time, but it could be wrong.

17 comments
¯_(?)_/¯
The second return value is the delta time. But another argument against while wait() do is for readability. Also some people use it without knowing how or why it works.
A lot of people use lava brick scripts without knowing how it works. A lot of people use free models even when they don't know how it works. We don't shun new players who use free models or wait as a condition. They're supposed to learn.
They should learn the right way to do things; not how to abuse hacks or learning old and bad ways.
Be a cool kid, and just do
while true do if wait(1) then -- code end end:>bad ^
It's the same exact thing as while wait(1) do, just more verbose.
No. By calling wait in the conditional portion you are using the return value as a condition. Conditions are YES or NO.
Conditions are not yes or no. They are truthy (not false or nil) or falsey (false or nil). Since "truthy" is so vague, anything can be used as a condition as long as it exists (and by "exists", I don't mean not nil. I mean that if it is a variable, it's a variable that has already been set, or an object in workspace that exists).
Your conditions should be yes or no. How can a number, be interpreted as yes or no (not in Lua)?
I'm pretty sure wait() would always be counted as true by the script, although the script recognizes that there is also a wait in the line. Forcing the code to pause until the wait finishes. So it likely wasnt a purposely implemented feature, and instead just happens due to wait()'s nature. Another thing to consider, is that many scripters discourage the use of infinetely looping-
using while loops, as it is usually a good precaution to add a way to break the loop / resume it in case needed for the future.
I don't think using one is better than using the other. It's only about the preference and maybe some microseconds difference in checking if the return value of wait() is "truthy". It's like arguing if you should use pcall or ypcall
wait(5)a man of culture, i see ;)@EtherealTrin, and for this very reason while wait() do works. It abuses the fact that numbers are truthy values and wait, returns a number. Two numbers, to be precise. The dependency is all on the return value of wait.
@incapaz the return value will never be removed is a point I've made. It never has since the very beginning and I highly doubt it ever will, since that was built in on purpose.
Main argument against using wait() as your condition is that people tend to forget what the condition is supposed to be used for. Using wait() as a condition and using a conditional statement inside it to break is not a solution to it. As long as you understand this, the decision is yours to make.