For example
local ran = false for i, v in pairs(game.Workspace.Model1:GetChildren()) do local intValue = v:FindFirstChild("DataValuel") if intValue.Value == 0 and not ran then ----do a thing ran = true; end --// do other things end end
What does Lua and not ran interpret as? I do not understand. ran is set to false, so and not ran would mean and not ran = false?
For a Lua conditional statement to be truthy, the condition must evaluate to a value that is not false
nor nil
. The not
keyword returns the boolean complement of the value that it precedes; if the value is truthy, then preceding the value with not
will return false
because the complement of a truthy value is a non-truthy value, or false
. If the not
keyword precedes a non-truthy value (false
or nil
), then true
will be returned because it is the only truthy boolean value that exists in Lua. Note that the not
keyword will always return a boolean.
not ran
is interpreted the same way. Since ran
refers to false
, preceding it with not
will return true
. If ran
were to refer to true
, then the condition would evaluate to false because not true
is equivalent to false
.
So, the conditional statement in question (if intValue.Value == 0 and not ran then
) will only have its body ran if those two statements evaluate to true because you're using the and
keyword. Think of reading it as "if the Value property of intValue
is equal to 0 and the complement of ran
is equal to true
then..."
Hey Seyfert,
-- Using Boolean variables inside the script -- local bool = true if not bool then print("It's false.") bool = true; else print("It's true") bool = false; end --[[ The above works like a toggle. When the bool value is true, it will run the second line of code and when it's false it will run the first line of code. --]]
-- Using Booleans to check if the UserDataValues exist -- local part = workspace:FindFirstChild("Part") if not part then print("The part doesn't exist.") end --[[ The above will check if the part exists and if it doesn't then it will print "The part doesn't exist." --]]
~~ KingLoneCat
Marked as Duplicate by TheeDeathCaster and cabbler
This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.
Why was this question closed?