Hello, I want to get a table value and check to see if it exists. I try to do this and I get a error saying attempt to call a table value
local function findAmt(inventory, item)
for i,v in pairs(inventory) do
print(v)
if v[item.Name] then
return v[item.Name]
end
end
end
for counter = 1,20 do
local slot = UI:WaitForChild("Slot"..counter)
if playerInventory[itemType][counter]{[item.Name] = findAmt(playerInventory[itemType], item)} then --Issue with this
print("a")
end
else
break
end
end
When I first look at it I notice you only have 1 = sign when you should always have 2 == when comparing values.
You should try out what @jakebball11 mentioned and also, why are there curly brackets in there? Did you mean do to this?
if playerInventory[itemType][counter][item.Name] == findAmt(playerInventory[itemType], item) then
if i add another equal sign it just gives me a syntax error, this is because of the curly brackets. If i remove the curly brackets it gives me another error saying attempt to index nil.
Then you have something that’s nothing in your table and you’re trying t o get something from nothing. Check your table and your variables
thats why its an else statement, I have code that adds it to the table if it isn’t already there
But the issue is, It’s not finding anything with the contents of itemType
or counter
and is erroring cause you’re trying to get a table from nil
When i print the table it is there which is why im confused
What is in your itemType and counter variables and what do you get when you print the table
itemType is the category that the item belongs in.

the counter just counts from 1 to 20.
Print the itemType and the counter in the variable, and print what you get when you do playerInventory[itemType]
and playerInventory[itemType][counter]

top one is itemType and bottom is counter
Now try printing playerInventory[itemType][counter][item.Name]
If i print the playerInventory[itemType][counter][item.Name]
it prints the amount but if i print playerInventory[itemType][counter][item] it prints nil

Okay I think it may be in the function, run the function normally outside of the if statement with the same tihngs given
v prints out 
i prints out the slot (ranged from 1 - 20 represented by counter) 
v[item] prints out nil and v[item.Name] prints out amount
Hmm, maybe put the result of playerInventory[itemType][counter][item.Name]
and findAmt(playerInventory[itemType], item)
in variables and compare those instead?
what do you mean? i don’t quite understand?
Wait I have a question, are all 20 slots filled? I think the issue is that one of those 20 slots is empty so it’s nil, and it tries to get a thing in nil, maybe change your loop to this?
for counter = 1,20 do
local slot = UI:WaitForChild("Slot"..counter)
if not playerInventory[itemType][counter] then continue end
if playerInventory[itemType][counter][item.Name] == findAmt(playerInventory[itemType], item) then --Issue with this
print("a")
end
else
break
end
end
so if there’s no counter for the inventory’s itemtype then it continues
the slots are not filled, im trying to check using playerInventory[itemType][counter][item] etc and there is an else statement that is used to fill up the slot if it isn’t taken.