How would I go by checking all values in a table to be set to true?

Hello everyone. So my issue is, i’m not sure on how I would go by checking all values in a table being set to true. Lets say:

local ThisTable = {Value1,Value2,Value3} --Not variables, actual bool values

I was thinking of using a for loop like:

for i=1,#ThisTable do
   if ThisTable[i].Value == true then
      --function
   end
end

However I know the function will trigger when one of the values goes true, which is not what I want.

Should I check each one manually or should I use a Metatable?

1 Like

You could try doing:

local ThisTable = {Value1,Value2,Value3}

for i, v in ipairs(ThisTable) do
  if v.Value == true then
    print("its true less goo")
  end
end

This is only a guess, I’m not sure if this will work.

2 Likes

No unfortunately, this does not work. I did try it with regular pairs() too

1 Like

If it doesnt work then it is your table/script fault, because in ipairs should work 100%. Does it print any errors?

1 Like

There are no errors being printing from this script in particular. I’m trying to have the script fire once all values are set to true, and not just one of them.

I’m still experimenting with ipairs().

Try using print(v) using script that @Downrest wrote

1 Like

I did, it did not output any result.

Could you show your entire code?

1 Like

So its tables fault. You should try putting all your values inside one folder and then using ipairs(folder:getchildren()) instead ipairs(table)
Edit:
sorry, i actually misread the post, so mine obv doesnt work.

1 Like

Well it’s kinda literally like this:

I’ll specify names as goes:


local Window = {script.Parent.BookValue,script.Parent.CTValue,script.Parent.GrassValue...} -- there are 8 values total

for A,B in ipairs(Window) do
   if B.Value == true then
      print("All values true")
   end
end

Thats it. There are no referencing errors either, no errors in output, or warnings in the script.

Ok, I shall see if replacing the table with a for loop does the trick.

Try this and see what it prints out:

local Window = {script.Parent.BookValue,script.Parent.CTValue,script.Parent.GrassValue...}

for A,B in ipairs(Window) do
	print(B)
	
	if B.Value ~= nil then
		if B.Value == true then
			print("All values true")
		else
			warn("VALUE IS NOT TRUE")
		end
	else
		warn("VALUE IS NIL")
	end
end
1 Like

Your problem is the values are Instances. You need to put .Value at the end of them so you get the value of them
So it’s something like this:

Wrong:
script.Parent.BookValue

Correct:
script.Parent.BookValue.Value

1 Like

Nope, this prints for every value being set to true individually, instead of all of them being true.

Ah yes sorry, forget to type in the website, editing now. But the .Value is in the original script.

Can you send us the explorer? Maybe that will help.

1 Like

Screen Shot 2022-01-31 at 2.53.04 AM

I updated the script with this folder in place. Script currently looks like:

for A,B in pairs(script.Values:GetChildren()) do
   if B.Value == true then
      print("All Values true")
   end
end 

EDIT: Nevermind. @Downrest, no values are being set to nil or outputting nil.

Do you change the values with any scripts? It might be giving an error because your script is a localscript and client does not replicate to the server

1 Like

The are remote events tied to the values from the server, and it worked undoubtably. So that isn’t the issue :sad:

Can you print all the values in the for loop? I’m curious
Can you also record a video of you playtesting if that is possible?

1 Like