I have a variable for the name of the method (i.e. local method = "GetChildren"
), so I first tried indexing the method by object[method]
, which works. Problem is, when I try to actually invoke the method, object[method]()
, I get the following error. I'm wondering if there's a way around this, because it's kind of a big part of what I'm making.
> print(Workspace["GetChildren"]) function: 08553E58 > print(Workspace.GetChildren) function: 08553E58 > for key, val in pairs(Workspace["GetChildren"]()) do print(key, val) end 19:47:04.245 - Expected ':' not '.' calling member function GetChildren
"Methods" (called by ':') are syntactic sugar for calling a function on an object. These kinds of functions have a 'self' argument. If you want to do something like you are trying to do, you must do the following:
local method = "GetChildren" object[method](object) --Alternatively, if you were calling a function with arguments local method = "FindPartOnRay" workspace[method](workspace, ray, ignore, bool)