I’ve been looking at scripts and stuff, and I’ve been wondering what this means and how it works.
local table = {"item1"}
local boolValue = Instance.new("BoolValue", workspace)
boolValue.Name = "ValueCheck"
boolValue.Value = table.find(table, "item1") or true and false
Basically, it’s checking if the “item1” in the table at the start of the script exists, if it doesn’t find it, then the boolValue will be false, but if it does find it, then the boolValue will be true, simple as that.
This doesn’t do what you want, table.find returns a number or nil, when it returns a number the entire condition will evaluate to a number giving you an error.
and has a higher precedence over or so true and false will first evaluate to false (because both conditions aren’t truthy), then number or false will evaluate to whatever number is if truthy, or it will evaluate to false when number is nil. To visualize, it’s the same as table.find(table, "item1") or (true and false)
I think what you’re looking for is table.find(t, "item1") ~= nil
Exactly as written, this will error because the local variable ‘table’ is shadowing the entire built-in table library, because of the naming conflict, so there is no find method to call.
If you change the variable name to something sensible, the code will work as expected, just not for the right reasons. It works because if table.find finds the element in the array, it returns the array index ( a number ), which is then implicitly converted to true when its assigned to boolValue.Value. If it does not find the element, it returns nil. nil or true is true, and true and false is false, so boolValue.Value is assigned false in this case.
Properly, the statement should be as @cody wrote it. The unnecessary additional logic being saved by type coercion is just very bad coding.