OOP in Module Script - Can't call method when passed through Bindable Event

Hello everyone,

I’ve been making a game and need to pass a metatable I made through a BindableEvent, and then call a method of the metatable from there. The reason why I’m not doing this all in one script is because I’ll eventually have lots of different scripts I’ll need to pass them through, so I’m doing it this way to reduce hardcoding. The problem is, I can’t call the method, because it says “attempt to call missing method of table”. I’ve searched through a few topics on here but none of them have really helped me. Here is my code:

--the code in the moduleScript that actually calls the BindableEvent.
--all items in ActionQueue are BindableEvents
function player:Update()
	if self.inAction then
		return
	end
	
	if #self.ActionQueue == 0 then
		return
	end
	
	self.inAction = true
	self.ActionQueue[1]:Fire(self)
	table.remove(self.ActionQueue, 1)
	self.inAction = false
end
--the function that gets called
script.Parent.Come.Event:Connect(function(character)
    --i've tried putting things like getmetatable, setmetatable, etc. here but nothing works
	character:PathfindToPoint(script.Parent.EnterPosition.WorldPosition) --where the error occurs
end)

I’ve also noticed that any changes made in the function that gets called don’t actually replicate to the original metatable. That might be why the problem is causing, but i’m unsure
(also if anyone asks, PathfindToPoint is also a function in the script, i tested it and it worked

If anyone could help, that would be appreciated! :slight_smile:

Had to learn this the hard way once. Unfortunately, functions don’t get passed through event instances. You’re better off moving the event to another function in the same or a different ModuleScript.

1 Like

rip

well thanks for letting me know, i’ll try to figure out how i’ll manage this

1 Like

fyi i managed to solve it by moving the function to a “Global” module script (handles like game logic and that)

1 Like

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