Module Issue (Im pretty new in OOP)

Hello, i was working on a interact system with a module. Im pretty new in OOP and i have this error

Basically all the interact system work good BUT it have functions for fire in other script and that functions don’t work

Like:

  function module:OnTriggered(Player)
   
  end

And when the function be called in the module that function should do this in other script:

function Item:OnTriggered(Player)
	print(Player.Name)
 end

I tried to change

local self = setmetatable({}, module)

to

local self = setmetatable(module, {})

and idk why but it works

But there is another problem, if i use local self = setmetatable(module, {}) instead of local self = setmetatable({}, module) the module only work in one object (like if it get stuck)

Another example more detailed:

–View of module:

if self.Raycast and RayCast then
   Pressing = false
   CurrentlyInteracting = false
   module:OnBlocked(self.Player, RayCast) --Aqui llama la function
   Functions:Tween(CooldownFrame, UDim2.fromScale(1, 0))
   break
end

--View of the other script

function Item2:OnBlocked(p, part)
    print("Triggered")
end

The function OnBlocked() basically is nothing in the module

function module:OnBlocked(p, Part)

end

Sorry if this post sucks, english is not my language

1 Like

Do you mean inheritance?
Here’s a link for you :slight_smile:
Object Oriented Programming in Roblox - Resources / Community Tutorials - DevForum | Roblox

1 Like

This looks fine, but you have to declare module like

local m = {}
m.__index = m

… for it to work.

The module already have that and still no work

Maybe you can show all (or at least a lot more) of your module code. Also show the code that is trying to call the module functions.

You have

module:OnTriggered()

and also

Item:OnTriggered()

which do not match. It’s not obvious what you are trying to do, so it will be hard to get help.

Sorry of the late reply.

–View of module:

if self.Raycast and RayCast then
   Pressing = false
   CurrentlyInteracting = false
   module:OnBlocked(self.Player, RayCast) --Aqui llama la function
   Functions:Tween(CooldownFrame, UDim2.fromScale(1, 0))
   break
end

--View of the other script

function Item2:OnBlocked(p, part)
    print("Triggered")
end

The function OnBlocked() basically is nothing in the module

function module:OnBlocked(p, Part)

end

I basically fixed placing the functions in self like:

function self:OnTriggeredCompleted(p)

end

and just calling the function like this:

  self:OnTriggeredCompleted(self.Player)