I want to go through a folder full of BoolValues and check if they are all set to true, if so then something will happen, if not then nothing will happen.
The code below checks through the folder, but doesn't do what I need. It just checks them individually and will execute the code even if only one BoolValue is set to true.
I hope this makes sense.
function CheckValues() for i,v in pairs (ValuesFolder:GetChildren()) do if v:IsA('BoolValue') and v.Value then print("All true") end end end
local Bools = ValuesFolder:GetChildren() local function CheckForAllTrue(Bools) for _,Boolean in pairs(Bools) do if (Boolean:IsA("BoolValue") and Boolean.Value ~= true) then return false end end return true end if (CheckForAllTrue(Bools)) then print("All true") end
Use a table and a variable:
local values = ValuesFolder:GetChildren() -- table function areTheyAllTrue(things) local var = true -- local variable to be returned for i,v in pairs (things) do if v:IsA('BoolValue') and v.Value then var = true else var = false break -- if even one is false, its set to false and breaks so it returns false immediatlely end return var -- returns the final value end end if areTheyAllTrue(values) then print("All values true") -- if its all true, print "All values true" end