so im making a npc class with oop and and ive already done all its functions(moving, eating, etc.) but im struggling with the constructor's function where it creates a new npc and makes it do the stuff automatically because in that function i implement npc's class methods to the npc model, until here, everything is fine, but then, as the 1st argument for _init() i must input the model, but if i do, for some reason, it says the methods arent there, so i tried, instead, inputting the metatable, which ALMOST works, because when i try using builtin model class' methods it says "expected : not . calling member function [function name]" (ive read abt this here: https://devforum.roblox.com/t/expected-not-calling-member-function/31935 but i still dont understand), heres an example:
local npc = {}
npc.__index = npc
local function _init(model)
--here i have an ai which automatically moves the npc around and makes it eat if food is found in front of him
end
function npc:move(position: Vector3)
--move it
end
function npc:jump(force: number)
--make it jump
end
function npc.new(name: string, position: Vector3)
local model = script[name]:Clone()
--do some stuff with the model such as naming it, positioning it and parenting it n other stuff
model = setmetatable(npc, {__index = model}) --works but all model's built-in functions error: "expected ':' not '.' calling member function [function name]" and i cant just use the actual model since it then doesnt
_init(model)
return model
end
return npc
I don’t want this to happen. I want to access the function itself because I’m wrapping things in metatables and I don’t want to have to write a special case for every possible member function, I just want to pass all of the arguments through a vararg. workspace.FindFirstChild(workspace, a, b) should work the same as workspace:FindFirstChild(a, ...