Get multiple buttons to change a value

Hello,
I’m currently creating a vending machine, however, I am unsure how to get multiple buttons to vend one item ie lets say i select 1 and 2 on a keypad it would = to 12 and so the vending machine would vend item 12. How do I do this?

My code so far:

local Tools = script.Parent.Tools
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local total = nil

if game.IsLoaded then
	Tools.Parent = ReplicatedStorage
end


for i, v in pairs(script.Parent.Screen.SurfaceGui.Select:GetChildren()) do
	if v:IsA("TextButton") then
		v.MouseButton1Down:Connect(function()
		end)
	end
end
local result = ""

for i, v in pairs(script.Parent.Screen.SurfaceGui.Select:GetChildren()) do
	if not v:IsA("TextButton") then continue end 
	v.MouseButton1Down:Connect(function()
		result ..= v.Text --the text of each button must be its number
		print(tonumber(result)) 
		--to erase the value(say for example with a specific button or after a time limit) just set it to "" 
	end)
end

I think it somewhat works actually, however, how would i separate my enter and cancel button? As they print nil.

v.Activated:Connect(function()
	--name the special buttons "Enter" and "Cancel"
	if v.Name == "Enter" then 
		print(result) --instead of printing, perform an action using the result
	elseif v.Name == "Cancel" then 
		result = "" 
	else
		result ..= v.Text 
	end
end)
for i, v in pairs(script.Parent.Screen.SurfaceGui.Select:GetChildren()) do
	if not v:IsA("TextButton") then continue end 
		v.Activated:Connect(function()
			--name the special buttons "Enter" and "Cancel"
			if v.Name == "Enter" then 
					print(result) --instead of printing, perform an action using the result
			elseif v.Name == "Cancel" then 
					result = "" 
			else
					result ..= v.Text 
				end
			end)
		end
	end)
end

So I did that and the enter button didn’t print the result, have I done something wrong?

Remove the third and fourth end/end).

I have more code so it errors if I remove it.

local Tools = script.Parent.Tools
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local enter = script.Parent.Screen.SurfaceGui.Select.Enter
local cancel = script.Parent.Screen.SurfaceGui.Select.Cancel

local UIinfo = TweenInfo.new(
	0.1, --Time
	Enum.EasingStyle.Sine, -- Style of door open animation
	Enum.EasingDirection.InOut, -- Direction of easing.
	0, -- Repeat count.
	false, -- Will it reverse?
	0 -- The delay time.
)


if game.IsLoaded then
	Tools.Parent = ReplicatedStorage
end


local result = ""

for i, v in pairs(script.Parent.Screen.SurfaceGui.Select:GetChildren()) do
	if not v:IsA("TextButton") then continue end 
	v.MouseEnter:Connect(function()
		local uithickness = v.UIStroke
		local tweenenter = TweenService:Create(uithickness, UIinfo, {Thickness = 4})
		local tweenleave = TweenService:Create(uithickness, UIinfo, {Thickness = 2})
		tweenenter:Play()
		v.MouseLeave:Connect(function()
			tweenleave:Play()
		end)
		

for i, v in pairs(script.Parent.Screen.SurfaceGui.Select:GetChildren()) do
	if not v:IsA("TextButton") then continue end 
		v.Activated:Connect(function()
			--name the special buttons "Enter" and "Cancel"
			if v.Name == "Enter" then 
					print(result) --instead of printing, perform an action using the result
			elseif v.Name == "Cancel" then 
					result = "" 
			else
					result ..= v.Text 
				end
			end)
		end
	end)
end

Also ty for all the help!

Replace the two loops with the following loop:

for i, v in pairs(script.Parent.Screen.SurfaceGui.Select:GetChildren()) do
	if not v:IsA("TextButton") then continue end 
	local uithickness = v.UIStroke
	local tweenenter = TweenService:Create(uithickness, UIinfo, {Thickness = 4})
	local tweenleave = TweenService:Create(uithickness, UIinfo, {Thickness = 2})
	v.MouseEnter:Connect(function()
		tweenleave:Cancel()
		tweenenter:Play()
	end)
	v.MouseLeave:Connect(function()
		tweenenter:Cancel() 
		tweenleave:Play()
	end) 
	v.Activated:Connect(function()
		if v.Name == "Enter" then 
			print(result) 
		elseif v.Name == "Cancel" then 
			result = "" 
		else
			result ..= v.Text 
		end
	end)
end 

Hmmm it doesn’t seem to print the result upon clicking enter???

Also I fixed the tween:stop(), It’s tween:cancel()

Nevermind, I had to change it from v.Activated to v.MouseButton1Down! It now works :smiley: thank you so much!