You already iterate, then check a value again… And you pass an instance, which doesn’t like to pass to functions. Try changing this loop to:
for i, v in pairs(products.Products) do
print(i, v) --let me know what outputs here
if v.Name == it.Handle.POSItem.Value then
--do other stuff here
end
end
What I want it to do is go through the module script to see if something equals something, and if it can find a match, then it will grab product name and price, but I don’t know how to do that like I said at the beggining of this post.
Next, we aren’t going to iterate. If we have the name as a string, my example array above uses that as the key. We could simply do:
local name
local cost
if module.Products[productNameHere] then --"productNameHere" would need to be equal to "Bread"
name = module.Products[productNameHere].Name
cost = module.Products[productNameHere].Cost
end
I want it to be able to be compatiable with multiple differnet products/items, and not just one, just by adding another POSitem into the tool in just configuring it in the products script for ease of use.
POSItem is a StringValue, so the number content is expressed as a string. This is not good for storing a number - you are therefore comparing a string and a number, which don’t mix. Just store the product’s name inside of POSItem, and use my example above that searches for the string key in the array.
One is for the key, and one is for the name. Setting the name variable equal to the key would store the secondary array inside, which we don’t want - instead we store the ["Name"] key.
And If I set product name here to bread, doesn’t that mean it will only be able to scan bread, which is a single item, which is I dont want that because I want it to scan multiple items with the ability to easily add more items
-- i recommend using promise but I won't use it in this example
for itemName, itemData in pairs(your_required_module) do
local Name = itemData.Name or "undefined"
local Cost = itemData.Cost or 0
-- do stuff
end
-- if you want to index thru it directly
local Name = your_required_module[itemName].Name or nil
local Cost = your_required_module[itemName].Cost or nil