Ok I did some research regarding PLUs. That helped to clear up what you are trying to do
PLU stands for Price look-up
So what happens is you put in the number ID of an item (for instance 1234), then you press PLU. What happens after is the the item with the ID (1234)'s price is added to the cash register.
(Cash Registers Jargon Buster - What Is A PLU? - YouTube Video that helped me out here)
Anyways so how can we do this?
First you will want to have a table with IDs and prices so that you can look it up them later
local ShopItems = {["1"] = 20, ["2"] = 40, ["3"] = 25}
Now we want to log the buttons
I will do this in a UI, however you can replicate this in the cash register later
What I have done is put all the buttons under one parent, which you could group them all
now continuing the code
local buttonsParent = script.Parent.Frame
for i,v in ipairs(buttonsParent:GetChildren()) do
if v:IsA("TextButton") then
v.MouseButton1Click:Connect(function()
end)
end
end
Your code may look something like this
local buttonsParent = script.Parent.ButtonGroup
for i,v in ipairs(buttonsParent:GetChildren()) do
if v:FindFirstChild("ClickDetector") then
v.MouseClick:Connect(function()
end)
end
end
Now we have to code ID creation, I will create a new variable. What we will do is add the number to the variable as we go on
local buttonsParent = script.Parent.Frame
local tempId = ""
for i,v in ipairs(buttonsParent:GetChildren()) do
if v:IsA("TextButton") then
v.MouseButton1Click:Connect(function()
tempId = tempId.. v.Name --Make sure you name each button to it's Value
end)
end
end
So far so good!
Now to code the PLU button. What we will do is get the value from the table of Ids and add it to a variable called total cost!
local ShopItems = {["1"] = 20, ["2"] = 40, ["3"] = 25, ["11"] = 110}
local buttonsParent = script.Parent.Frame
local tempId = ""
local totalCost = 0
for i,v in ipairs(buttonsParent:GetChildren()) do
if v:IsA("TextButton") then
v.MouseButton1Click:Connect(function()
tempId = tempId.. v.Name
print(tempId)
end)
end
end
script.Parent.PLU.MouseButton1Click:Connect(function()
if ShopItems[tempId] then --Makes sure that the ID is in the table
totalCost = totalCost + ShopItems[tempId]
print("Cost = "..totalCost)
end
tempId = "" --Resets the Id to be used again!
end)
So big takeaways
You can add strings/numbers to the end of a variable with 2 dots (. .)
local var = "Hello"
var = var.." World ".. 123
print(var) -- Prints Hello World 123
Here is the file I made for the testing, GL!
Cash Register Test.rbxl (23.0 KB)