OOP HELP | How to keep SELF while sending in arguments?

I’ve created a function using a metamethods to keep track of other tables

Example code:

-- Module
local Module = {}
local functions = {}
functions.__index = functions

Module.new = function()
	local Metatable = {
		variable = "Hello"
	}

	setmetatable(Metatable, functions)
	return Metatable
end

function functions.Place_Object(self, args)
	print(self.variable) -- prints "Goodbye"
	print(args) -- Nil
end
return Module
-- Script
local Module = require(module)

Remote_Function.OnServerInvoke = function(player, func)
    local args = {
        variable = "Goodbye"
    }
    local NewObject = Module.new()
    NewObject[func](args)
end

The self variable is getting replaced with the arguments and I’m trying to know if it’s possible to keep the arguments while keeping self as the Metatable?

  • I need the function to print “Hello” instead of “Goodbye”
  • I cannot change the function syntax to “:” because I’m calling the function using a variable
2 Likes

Did you share the wrong code or omit something important? Your code should error, as NewObject does not have a function property.

1 Like

There there’s no error, it has a metatable with __index so it calls fine

Edit: I also tested the code so and it runs

1 Like
local Module = require(module)

Remote_Function.OnServerInvoke = function(player, func)
    local args = {
        variable = "Goodbye"
    }
    local NewObject = Module.new()
    NewObject[func](NewObject, args)
end

Sidenote, but I’m not sure why you would want the client to be able to decide what the server does with its object. ignore

2 Likes

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