Can't reference table index from variable?

Hello. I’m trying to set a table index using a function, by passing the index number to it. Like this:

addItemToInventory(2, 5

This is the function:

function addItemToInventory(itemIndex, inSlot   
 inventoryBag[inSlot] = itemIndex  
  
end  

inSlot is the variable and I’m passing 5 to that from the first code snippet…

When I run this I get a Runtime error:

Runtime error  
 ~/Project/inventory.lua:25: table index is nil  

What am I doing wrong?

Thanks!
[import]uid: 144504 topic_id: 26597 reply_id: 326597[/import]

bump. [import]uid: 144504 topic_id: 26597 reply_id: 108068[/import]