I am trying to get a text value to change by calling a function to get a value. I call this function a lot before this moment but when I call it i get an error saying invalid argument #3 (string expected, got nil)
I call this function using this line:
currSlot.Amount.Text = findAmt(playerInventory[v], currItemName)
the function is:
local function findAmt(inventory, item)
for i,v in pairs(inventory) do
if v[item.Name] then
return v[item.Name]
end
end
end
im not sure what is causing this to occur because even if i do tostring(currItemName) it still gives me an error.
try this
currSlot.Amount.Text = findAmt(playerInventory[v.Name], currItemName)```
I tried that but then I just got invalid argument #1 to 'pairs' (table expected, got nil)
p49p0
(Citrullus)
June 15, 2021, 9:37am
4
then the inventory is nil
Probably the thing which is happening here ig
If i print out the inventory it prints out the contents i get values.
playerInventory[v]
What is V?
Should you be passing in playerInventory instead of a value in that table?
I have my inventory divided into sections so v represents a number 1-4. I also have an if statement that checks to see if the item is there.
peepo12343:
if v[item.Name] then
try if v[item.Name] ~= nil then
print()
if it didn’t print then check the
inv loop bc v is probably nil in that loop
it printed the value so its not nil in the inv loop, any other suggestions?
If currItemName being passed in is a string then change item.Name to item. You may be referencing .Name on a string hence the nil error.
CurrItemName is being split from ["Coal"] = 1 so coal is the item name and the amount is 1.
edit: I changed item.Name to item and it didn’t work
before setting the Amount.Text print the function
local test = findAmt(playerInventory[v], currItemName)
print(test)
and show me the output
yes bc as i told u v is currently set to nil
edit: there is something wrong in the loop i guess
any suggestions that i could use to fix this?
I usually start doing
print(typeof(variable)) to track down why my comparators are misbehaving.
MrchipsMa
(MrchipsMan)
June 15, 2021, 10:01am
18
try showing the script for the v representing the numbers
What is output of
for i,v in pairs(item) do print(i,v) end
Razor_IB
(spoodr)
June 15, 2021, 10:03am
20
Inventory isn’t nil , there is no value in the table inventory with the key v.Name