Detect which button was pressed when referring to all buttons from a table

Sorry to be back so soon, but I have a question. I have this function below that activates when any of the buttons in a table is pressed. My issue is, how would I know which button the player pressed while keeping this format? I know I can make a function that activates when a specific button is pressed instead of one inside the table but i can keep my code shorter by detecting input from any of them then having the script know which one was pressed anyway so I don’t have to copy-paste functions.

Any help is appreciated, thanks.

		v.Button.MouseButton1Down:Connect(function()
			if confirmation == false then
				confirmation = true
				for i, w in pairs(Classes) do
					if w["Button"] then
						if v ~= w then
							w.Button.Visible = false
							script.Parent.SelectedClass.Value = w["ID"]
							script.Parent.Yes.Visible = true
							script.Parent.No.Visible = true
						end
						script.Parent.TopText.ClassDesc.Text = "You have chosen to go with "..w["Name"]..". Are you sure? This can be changed later."
						SClassCheck.Value = w["ID"]
						print(w["Name"]..w["ID"])
					end
				end
			end
		end)

I resolved this myself:

v.Button.MouseButton1Down:Connect(function()
			if confirmation == false then
				confirmation = true
				local class = Classes[i]
				for i, w in pairs(Classes) do
					if w["Button"] then
						if v ~= w then
							w.Button.Visible = false
							script.Parent.SelectedClass.Value = class["ID"]
							script.Parent.Yes.Visible = true
							script.Parent.No.Visible = true
						end
						script.Parent.TopText.ClassDesc.Text = "You have chosen to go with "..class["Name"]..". Are you sure? This can be changed later."
						SClassCheck.Value = class["ID"]
					end
				end
			end
		end)

What I did was check the index from a previous part of the script and made a few other changes as seen in the script above.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.