Im stuck on this store checkout script Im making

Core script that runs when an item has been scanned:

local products = script.Parent.Products
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

function onScan(product)
	
	-- Code will run when item is scanned and accepted, which will check item name and cost from module script and add it to the total and put it on the list of things scanned
	
	
	
end

sensor.Touched:Connect(function(item)
	if item.POSitem.Value ==  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
		print("It is a valid part")
		onScan(item.Handle)
	end
end)

Module script that holds all product data:

local module = {}

	Products = {
		
		[1] = {
		["Name"] = "Bread",
		["Price"] = "2.99",
		},
		
	}
		
return module

Tool Im trying to make scannable:
Screenshot 2024-02-24 173547

Checkout model:
Screenshot 2024-02-24 173708

What I need help with is how to check if something in the tool equals something in the module script. I explained in the comments of the core script

Inside POScore is the total/current price value

First way:

Script:

local products = 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

function onScan(product)
	
	-- Code will run when item is scanned and accepted, which will check item name and cost from module script and add it to the total and put it on the list of things scanned
	
	
	
end

sensor.Touched:Connect(function(item)
	if item.POSitem and products.Products[item.POSitem.Value]  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
		print("It is a valid part")
		onScan(item.Handle)
	end
end)

Module:

local module = {}

Products = {
    ["Bread"] = {
        ["Price"] = "2.99",
    },
}

return module

Second way:

Script:

local products = 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

function onScan(product)
	
	-- Code will run when item is scanned and accepted, which will check item name and cost from module script and add it to the total and put it on the list of things scanned
	
	
	
end

sensor.Touched:Connect(function(item)
	if item.POSitem 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
        for i, v in pairs(products.Products) do
            if products.Products[tostring(i)]["Name"] == item.POSitem.Value then
                print("It is a valid part")
                onScan(item.Handle)
            end
        end
	end
end)

Module:

local module = {}

module.Products = {
    ["1"] = {
        ["Name"] = "Bread",
        ["Price"] = "2.99"
    },
}

return module

i think its this that you want

Okay thanks, I’ll try that when I can get back on my pc! Im on my phone right now, hopefully it works!! :slightly_smiling_face:

When I use this script, it only finds my character parts and not the tool.

Sorry I accdently marked solution when I tried pressing the reply button. But its not working still. Which I don’t know any way to unmark it so I might have to make a new post.

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

function onScan(product)
	
	-- Code will run when item is scanned and accepted, which will check item name and cost from module script and add it to the total and put it on the list of things scanned
	
	
	
end

sensor.Touched:Connect(function(item)
    local it = item.Parent:FindFirstChildWhichIsA("Tool")
	if it and it.Handle:FindFirstChild("POSitem") 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
        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")
                onScan(it.Handle)
            end
        end
	end
end)

see if this works

Okay, I’ll go ahead and try that!

Now its not showing up anything in the output

try this to see what appears in the output

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")
                    onScan(it.Handle)
                end
            end
        else
            print(`POSitem dont exist inside {it.Name}`)
        end
    else
        print("item not found inside the character.")
	end
end)

I have used some code from the roblox ai assistant and this is what it looks like now:

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.Scanner.Sensor

local valueToCheck = nil

function onScan(product)

	-- Code will run when item is scanned and accepted, which will check item name and cost from module script and add it to the total and put it on the list of things scanned
	print()
	
	local found = false

	for key, value in pairs(products) do
		if value == valueToCheck then
			found = true
			break
		end
	end

	if found then
		print("The value was found in the module script.")
	else
		print("The value was not found in the module script.")
	end

end

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)

But it doesnt print “The Value was found in the module script.” when checking for if the item equals one of the things in the module script.

Did you look at the toolname he uses? He says he get’s an error but his toolname is litterly POS Test Tool

It supposed to check inside of the tool if theres an IntValue named POSitem

What about just making this:

sensor.Touched:Connect(function(item)
	if item:FindFirstChild("POSItem") and products.Products[item.POSitem.Value] then 
		print("It is a valid part")
		onScan(item.Handle)
	end
end)

It doesnt print anything when I use that.