Firstly, I do not want to use the Mouse object, so MouseButton1Click is not an option. I want to use UserInputService, but my solution still seems unclean.

ModuleScript:

function GuiModule.Click(Input)
    if Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType == Enum.UserInputType.Touch then
        return true
    else
        return false
    end
end

LocalScript:

local GuiModule = require(game.Players.LocalPlayer.PlayerGui.GuiModule)

Button.InputEnded:Connect(function(Input)
	if GuiModule.Click(Input) then --I really have to write an if statement for every InputEnded event?
		print("Button clicked")
	end
end)

Ideally, I want something like this, where .Clicked is a custom event that utilizes object-oriented programming in a module script. I've looked into metatables and metafunctions but I can't fully grasp their functionality to implement this, if its possible.

local GuiModule = require(game.Players.LocalPlayer.PlayerGui.GuiModule)

Button.Clicked:Connect(function(Input)
    print("Button clicked")
end)

2 comments

2

MouseButton1Click was never deprecated.

0

Yeah but I see people recommend not using it