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.)
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
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.