Improving this script of handling bindable event

Let’s say i have a script with multiple bindable event as its child. Then a child module communicate to the main script using instanced bindable event. The parent script thus handle communication from child moduleScript as follow :

Event_Play.Event:Connect(function(reqType,...)
	local reqFunc = {
		["Solo"] = function()
			
		end,
		["Multiplayer"] = function()
			
		end
	}
	
	if reqFunc[reqType] then
		reqFunc[reqType](...)
	end
end)

Event_Save.Event:Connect(function(reqType,...)
	local reqFunc = {
		["Add"] = function()

		end,
		["Remove"] = function()

		end,
		["Rename"] = function()
			
		end
	}

	if reqFunc[reqType] then
		reqFunc[reqType](...)
	end
end)

This script work fine. Nothing wrong and nothing in shamble that i require urgent fix. And i kinda like handling bindable this way. Don’t have to instance tons of bindable, only need one per communication category, and easier to read.

The small issue is, im wondering if there’s a way to improve the writing of the script handling. So i don’t have to rewrite another table of function, then rewrite another :

if reqFunc[reqType] then
    reqFunc[reqType](...)
end

You could have a single BindableFunction that handles everything and a single table, for example:

local functions = {}

-- Play functions
functions["Play"] = {}

function functions.Play.Solo(...)
	-- ...
end

function functions.Play.Multiplayer(...)
	-- ...
end

-- Save functions
functions["Save"] = {}

function functions.Save.Add(...)
	- ...
end

function functions.Save.Remove(...)
	- ...
end

Event.Event:Connect(function(type_, name, ...)
	if functions[type_] and functions[type_][name] then
		functions[type_][name](...)
	end
end

If you want to stick with multiple BindableEvents you could have an object oriented module that handles this that has an addHandler method (or something along the lines), and a handle method. Let me know if you need help with that

I started to considering your method, up until i read the last line, which looks like it need another argument, which, personally looks more cluttered to me.

I think im more comfortable with the multiple bindable style, since its easier to read for me personally and give me easier time to keep track.

As for your last paragraph. Can you elaborate more on your OOP handler idea?