A few table issues?

So, I’m trying to make an inventory buy system. Well, it hasn’t gone accordingly to plan.

All of the values have a value of one while the values should all have different values.

Here’s my script:


 inventorysystem = {}
function inventorysystem.insert(item,price,cash,plr)
	local inventory = {}
	if cash.Value >= price then
		cash.Value -= price
		table.insert(inventory, item.Int.Value)
		local value = table.find(inventory, item.Int.Value)
		local int = Instance.new("IntValue")
		int.Name = item.Name
		int.Value = value
		int.Parent = plr.Inventory
		print(value)
		end
end
return inventorysystem

Result:

image

image

image
image
image

Maybe I’m using table.find incorrectly?

And no, please don’t give me an answer like, “You don’t need tables”, I do need tables for this as I’m going to use tables throughout the code. Also, yes I have checked all the values.

1 Like
local inventory = {}

You’re only adding values to a local table that is created during function execution and immediately garbage collected after the function ends.

1 Like