Module script concept, how would I get it to work?

This is a script that gets a module script (working).

for i, v in pairs(attack_events[script.Name]:GetChildren()) do
	if not(exceptions[v]) then
		v.OnServerEvent:Connect(function(player,info)
			attacks.v(player,info)
		end)
	end
end

Is it possible to call an attacks function without using its exact name ,
an example would be lets say the attacks module had a function called “slash”
I could say attacks.slash(), could I say attacks.v() assuming v was slash. Obviously this does not work, I am wondering if it can be done. ANY response is appreciate.

1 Like

You can index a name without directly using it, just use [v]. Remember these symbols receive a string to index (["Slash"]) instead of directly indexing like dot does, so when using a variable which returns a string there shouldn’t be any problems.

local Names = {
	"Slash"
}

local Funcs = { }

Funcs.Slash = function()
	print("Slash")
end

for _, v in ipairs(Names) do
	Funcs[v]()
end
1 Like