Trying to recreate "Mouse.KeyDown" with OOP

  1. What do you want to achieve? Keep it simple and clear!

The title says its all. Im trying to recreate the deprecated mouse function “Mouse.KeyDown()”.

  1. What is the issue? Include screenshots / videos if possible!

(I recently learnt OOP so im not quite a pro with it yet. So sorry if this is an easy fix)

I can create the signal n everything. But the problem occurs when i want to connect a callback to the Signal

Code for creating a new signal(Just a returned UserInput Signal)


Signal module

local module = {}


function module.new()
	
	local self = setmetatable(module, {})
	self.Signal = game:GetService("UserInputService").InputBegan

	return self
end



return module

Main module

local module = {}
local SignalModule = require(script:WaitForChild("Signal"))


function module.new()
	
	local self = setmetatable(module, {})
	self.Signal = SignalModule.new()
	
	return self
end



function module:Connect(Func)
	
	self.Signal:Connect(Func) -- // Problem occurs here. Since the "Func" is a callback i cant access the InputObject?.
	
end

How would i be able to connect the first arg(Callback) AND access the InputObject returned from UserInputService??

Your setmetatable is wrong should be
local self = setmetatable({},module)

Secondly, you should have the :Connect method to be in the signal module and not in the main module

1 Like