so i kind of want my code to look like this..
local function something() -- make sure to put this inside a pcall() function local item for i,v in pairs(slot:GetChildren()) do -- gets item inside selected if v:IsA("Model") then item = v end end func(item.Name)(item.Animation,slot.Name) -- item.Name == the func name end something() end
so basicly my idea is to put hole bunch of functions inside a script and when a player wants to use a item. it calls the function by the name of the item. for example if somone used a apple the script would find whats inside the slot (apple) and then call the function with its name and the arguments. let me know if this is kind of hard to understand and ill try to explain it better. thanks
Functions, like any other variables, can be stored in tables.
local funcs = {oneFunc, twoFunc, blueFunc, redFunc}
You can then access the functions stored in the table just like any other item as well:
funcs["oneFunc"]
You can also call it:
funcs["oneFunc"](arguments)
Another example:
local functionName = "redFunc" funcs[functionName](arguments)