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

Should I put wait() in my conditionals?

##Question Information

A user answered a question. It included while wait() do end. Another user posted in the comments of that answer to never use wait() as a conditional?

##Question

What makes while wait() do end worse than while true do wait() end?

1 answer

✓ Accepted answer

###while CONDITION do runs code whilst the condition specified is true, breaks if the condition becomes false or nil.

while wait() do
    --...
end

###That code only runs because the wait function returns the time waited as the first value, and the time since the program started as the second value. It would not run at all if the return value were false or if it didn't return at all. And because that value is truthy in Lua, that code runs indefinitely.

while true do
    wait()
    --...
end

###You should instead consider using the latter, as it is slightly faster and is more expressive than the former. For these reasons, use while true do.

2 comments

0

What does truthy and falsey mean (knowing that the opposite of true is false, so, the opposite of truthy is falsey)?

0

Numbers, strings, tables, objects, and events are truthy in Lua. false and nil are falsey values.

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