Basically, I have a folder with boolvalues of whether a player can craft a certain object, and i want to know how many of the values are true so I know how to organize the GUI.
local isTrue = 0
local boolFolder = --define the folder
for i,v in pairs(boolFolder:GetChildren()) do
if v:IsA('BoolValue') then
if v.Value = true then
isTrue += 1
end
end
end
2 Likes
I created a function in which you can use to find the number of True Bool Values, this will give you a table of the True Bool values as instances.
local function Check_For_True_Bool_Values(FolderObj)
local NTBT = {} -- the table
for i,v in pairs(FolderObj:GetChildren()) do
if v:IsA("BoolValue") then--Some checking.
if v.Value == true then--More checking.
table.insert(NTBT, v)
end
end
end
return NTBT
end
local NTBT = Check_For_True_Bool_Values(workspace.Folder) --NTBT is the table
--worspace.Folder is the placeholder for the location to check the bool values in.
print(NTBT) --prints the table of the true bool values in the output.
print(#NTBT)--prints the number of true bool values in the output.
You can find the number by putting #
before the table. In the first parameter of the function, set it as the folder with the bool values. Hope this helps!
You put True
instead of true
, might wanna fix that
local isTrue = 0
local boolFolder = --define the folder
for i,v in pairs(boolFolder:GetChildren()) do
if v:IsA('BoolValue') then
if v.Value == true then
isTrue += 1
end
end
end
2 Likes
OP will also need to change =
to ==
for comparison.
Even better would be to remove the comparison altogether - comparing a boolean to a boolean is redundant. You can just do if v.Value then
.