How would I get all the bool attributes within a script?

Basically I am attempting to use attributes as a simpler form of just repeating strings within a variable. It’s much more nice looking, and easier to use then just editing the values within.

Here is a script I came up with, not sure why it doesn’t insert any values at all.

local totalCards = script.Parent.Parent:GetAttributes()

print(totalCards)

for i ,_ in pairs(totalCards) do
	if i == false then 
		table.insert(deny, i.Name)
	else 
		table.insert(accept, i.Name)
	end
end

I really have no clue what’s gone wrong within the script; or of any other methods to get around with something like this.

Any help would be appreciated!

(I also haven’t found any topics related to this, sooo if there are to be any new topics of the same thing, sorry.)

This is an extremely basic lúa question Programming in Lua : 2

I’m trying to use attributes, not BoolValues by themselves. I don’t know how I’m going to get multiple bool attributes from within the model.

Instance:GetAttributes()

EDIT: My bad I didn’t read the full script you sent

As @Aegians said, you should use typeof to get the type of the attribute rather than using i == false. Another thing I notice is that you shoudl use the 2nd value in the pairs loop, as that’s the value in the attribute, the first value is the name of the attribute, so maybe something like

for i,v in pairs(totalCards) do
	if typeof(v) == "boolean" then 
		table.insert(deny, i)
	else 
		table.insert(accept, i)
	end
end

If you need the type to not be boolean for the deny table, then change == to ~= to put booleans in the accept table

1 Like

I think I accidently didn’t state in particular what I needed to happen.

image

This is my bad; what I was trying to do is getting if the bool attribute is to be false, or true, and add them to a table of deny and accept at needed

So you want to put false values in a deny table and true values in an accept table?

local totalCards = script.Parent.Parent:GetAttributes()
local deny = {}
local accept = {}

print(totalCards)

for name, value in pairs(totalCards) do
	if value == false then
		table.insert(deny, name)
	else
		table.insert(accept, name)
	end
end

print("Accepting")
print(accept)
print("Denying")
print(deny)

for i, v in pairs(table) do returns 2 things, i = index and v = value, it won’t matter what name you give for them, for field, answer in pairs(table) do will still return field = index and answer = value.

This has 2 behaviors, in tables it returns the index which is an integer and the value, and in dictionaries it returns the index which can be anything and the value.

GetAttributes() returns a dictionary NOT a table, so you loop through all the dictionaries values, where name or index is the attribute name and value or v is the value of that attribute.

1 Like