Is there a better way to get input detection from GUI Button that isnt an entire function?

I am making a drum set that, when you press a key, plays a sound. I am trying to adapt this to work for mobile using buttons on screen. Currently this is the code I have for keyboard which is a local script located within StarterPlayerScripts that tells a server script to play a sound using RemoteEvents.

-- FOLLOWING VARIABLES ARE ALL VARIABLES THAT APPEAR IN THE ENTIRE SCRIPT (to lazy to sort and find which ones the function uses :p) --

-- Player Info
local player = game:GetService("Players").LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
controller = false
mobile = false
keyboard = true

-- Drum Info
local inputService = game:GetService("UserInputService")
local drumSounds = game.ReplicatedStorage.Drums
local state = true
pedal = false

-- Gui Info
local GUI = game.Players.LocalPlayer.PlayerGui.Drums
local keyboardGUI = GUI.PC
local consoleGUI = GUI.Console
local mobileGUI = GUI.Mobile


inputService.InputBegan:Connect(function(input)
	if not state then
	
		-- Following if statements send signal to server when user clicks key input
		if pedal == false and input.KeyCode == Enum.KeyCode.J then
			drumSounds.OpenHi:FireServer()
		end
		
		if pedal == true and input.KeyCode == Enum.KeyCode.J then
			drumSounds.CloseHi:FireServer()
		end
		
		if input.KeyCode == Enum.KeyCode.K then
			drumSounds.Ride:FireServer()
		end
		
		if input.KeyCode == Enum.KeyCode.N then
			drumSounds.Tom1:FireServer()
		end
		
		if input.KeyCode == Enum.KeyCode.C then
			drumSounds.Tom2:FireServer()
		end
		
		if input.KeyCode == Enum.KeyCode.L then
			drumSounds.TomF:FireServer()
		end
		
		if input.KeyCode == Enum.KeyCode.A then
			drumSounds.Snare:FireServer()
		end
		
		if input.KeyCode == Enum.KeyCode.B then
			drumSounds.Kick:FireServer()
		end
		
	end
end)

Now my plan was to do something similar for mobile but I don’t want do write and entire new function if I don’t have to. From my knowledge (still a beginner coder) the only way I know of doing this would to do something such as GUIbutton.Activated:Connect(function()) or putting a script into every single Button and putting script.Parent.MouseButton1Click:Connect(function())

So to repeat myself: is there a better way to tell when a player interacts with a GUI Button that isn’t just an entire separate function for each button?

is it possible to just use one remotevent and request to the server what note you wanna play?

Not from my knowledge, but then again, I could be doing what im trying to do redundantly. In this forum post I have about all of my code and and RemoteEvents listen out which you could quickly look through.

TLDR each RemoteEvent is a different sound. The reason why I am doing this is so when a player clicks a key, it sends a signal to the server, which plays the corresponding sound.

i’m trying to say that you dont need a seperate remotevent for each single sound; the arguments you can pass into the server exist for a reason.

anyways, i think you can set a string attribute for each button in studio that’s the name of the sound it plays, then loop through each gui button like this:

local buttonsParent = --[[whereever u keep ur buttons]]

for i, btn in pairs(buttonsParent:GetChildren()) do
    local note = btn:GetAttribute('Note') -- u can rename to whatever u name ur attribute

    if not note then
        warn('No attribute assigned to: '.. btn.Name)
        continue
    end

    local signal = btn.Activated:Connect(function()
        drumSounds.PlaySound:FireServer(note)
    end)
    
    btn.AncestryChanged:Once(function(c, parent)  -- disconnecting events just in case for the sake of memory
        if parent then return end
        signal:Disconnect()
    end)
end

then in the server you can identify which sound the client requests using the strings given

edit: mb forgot to make the signal events

Ill give this a shot tomorrow when I have time! Pre-marking as solution for now