Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Making a custom event to detect mouse clicks?

Asked by
GShocked 145
9 days ago
Edited 9 days ago

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
MouseButton1Click was never deprecated. Feahren 5485 — 9d
0
Yeah but I see people recommend not using it GShocked 145 — 9d

Answer this question