How to match a table function name with another table same name

So what i’m trying to do is match a table string name with another table function name, here’s the code:

local AllSkills = {
		"PilarBelowPlayer",
		"PilarSomewhere",
		"EarthShield",
	
}

local SkillFunctions = {
	PilarBelowPlayer = function(Character:Model)
		print("XD")
	end,
}

SkillsRemote.OnServerEvent:Connect(function(Player, Skill:string)
	print(Player)
	for _, v in ipairs(AllSkills) do
		if Skill == v then
			print("YES")
			for __, skill in ipairs(SkillFunctions) do
				--[[Here the skill name  would match with
 the Skill Function name ("PilarBelowPlayer" as an example, and then it would 
search in the SkillFunctions table any function that is named the same as the
 Skill name, and after there is a match, the function would be 
executed)]]
			end
		else
			print("No")
		end
	end
	
end)

I’ve tried to use table.find but it didn’t work, i’m not new in Lua but not an expert too, and this is the first time i’m using tables so I don’t understand some stuff (most of it, at least for now), any help and explanation would be really appreciated!

1 Like

You should just be able to do SkillFunction[Skill]()

2 Likes

or table.find(SkillFunctions, SkillName).

Yeah that should work because:


local AllSkills = {
	"PillarBelowPlayer",
}

local SkillFunctions = {
	PillarBelowPlayer = function()
		print("hello")
	end,
}

SkillFunctions[AllSkills[1]]() -- prints hello

that will always return nil, because table.find does not work on dictionaries. (It won’t error, but it won’t find any keys)

1 Like

that worked, tysm. im just dumb, but i learned a new thing from tables

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