Im making a store checkout POS. Read below to see my problem.
I need help figuring out how to check all things from a module script using a for loop, an d then seeing if one of those equals a specfic value from a tool that was scanned, and if it does then recieve data from the module script for that specfic value found inside the tool scanned.
The value to be checked is an IntValue called POSitem inside the tool, which it should be checked when the item gets scanned, which I don’t know how to do that because I don’t even really know how for loops work, as I never really used them before in the past.
I made another post about this a few weeks ago, which I decided to make a new one because everyone who replied is posting a bunch of scripts that dont work for the thing Im trying to make, probably because I didnt explain it very well, but now Im trying my best to explain it here. and now the few people who orginal replied to me dont even really say anything no more, probably because it’s a really old post. Im new to the devforum just got in like 2 months ago.
My script:
local products = require(script.Parent.Products) --supposing that this is the module
local screen = script.Parent.Screen
local ui = screen.SurfaceGui.Frame.Background
local start = ui.Start
local cancel = ui.Cancel
local currentpriceui = ui.CurrentPrice
local currentprice = script.currentprice
local sensor = script.Parent.Sensor
local valueToCheck = 0
function onScan(product)
-- Code here is what is supposed to check the module script
end
script.Parent.Sensor.Touched:Connect(function(item)
local it = item.Parent:FindFirstChildWhichIsA("Tool")
if it then -- Here is where Im stuck trying to figure out how to check if the POSitem value equals one of the things in the module script
if it.Handle:FindFirstChild("POSitem") then
print(`POSitem exist inside {it.Name}`)
for i, v in pairs(products.Products) do
if products.Products[tostring(i)]["Name"] == it.Handle.POSitem.Value then
print("It is a valid part")
valueToCheck = it.Handle.POSitem.Value
onScan(it.Handle)
end
end
else
print(`POSitem dont exist inside {it.Name}`)
end
else
print("item not found inside the character.")
end
end)
And the module script:
local module = {}
module.Products = {
["1"] = {
["Name"] = "Bread",
["Price"] = "2.99"
},
}
return module
So the whole point of it is, is when ever someone scans an item, if it is a valid item that has the intvalue “POSitem” inside of the tool, it will use that number inside of the intvalue and check it with the module script. For example, if it was the number 1, it will find the one value inside of the module script and grab back the Name and Price value, which the price will add onto the current price value inside of the main script, and the name of the item will appear on screen. After all items are scanned, the cashier can press start transaction which will activate the card reader/pinpad thingy for the customer to pay. After the customer pays, the current price value will be set back to 0 and all item names on screen will dissapear. Which right now Im mainly focusing on the scanning process to work.