MouseButton1Click Frame

Hey everyone,

I have a quick question: Is It possible to use MouseButton1Click on Frame

and If not what are the alternatives for MouseButton1Click on frame

Thanks for reading.

4 Likes

There is no RBXScriptSignal for MouseButton1Click on a frame, no. Though you could use UserInputService but I cannot guarantee you, that you will get the best results :cry:

2 Likes

No, it’s not possible, you should check for another way to conect the MouseButton1Click.

1 Like

Best alternative is to make transparent button all over the frame.

1 Like

Haha I had this idea in mind… but there is areas It can’t cover

Well only GuiObjects that have MouseButton1Click signal are TextButton, ImageButton.

1 Like

Whoops, there is a way!

You could listen for the InputBegan event on a frame;

local Frame = script.Parent

Frame.InputBegan:Connect(
    function(InputObject)
        if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
            ...
        end
    end
)
22 Likes

This will work only for PC (just saying) but great idea how to go around this.

2 Likes

If you want to create a sort of custom button for whatever reason, you can first detect if the mouse ishovering over the frame. If so, respond whenever the mouse clicks.

local MouseHovering = false
local Frame = path.to.frame

local function OnFrameClicked()
	print("Click!")
end

Frame.MouseEnter:Connect(function ()
	MouseHovering = true
end)

Frame.MouseLeave:Connect(function ()
	MouseHovering = false
end)

game:GetService("UserInputService").InputEnded:Connect(function (input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and MouseHovering then
		OnFrameClicked()
	end
end)

Note this doesn’t detect mobile input. I’m just sharing this with you to get you started! (This also isn’t tested in Roblox Studio)

4 Likes

Thanks for everyone who helped…

@Maya70i & @Afrxzo Thank you :smiley:

This should work on mobile [NOT TESTED]
Read the reply this doesn’t work

local Frame = script.Parent
local marketplace = game:GetService("MarketplaceService")

Frame.InputBegan:Connect(
	function(InputObject)
		if InputObject.UserInputType == Enum.UserInputType.MouseButton1 or Enum.UserInputType.Touch then
			...
		end
	end
)
2 Likes

You can just put an invisible textbutton over it if you really want

1 Like

That wouldn’t work because of how or operates.


Just do:

if table.find({Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch}, InputObject.UserInputType) then
4 Likes

oh, sorry. I am kind of new to this.

1 Like

Oh perfectly! Nice idea, U explain this perfectly!

i know this post is old but isnt it simpler to just do

if InputObject.UserInputType == Enum.UserInputType.MouseButton1 or InputObject.UserInputType == Enum.UserInputType.Touch then

instead ? :sweat_smile:

You could do that if you want; I like to use table.find if I’m detecting a large number of different inputs

i see, although i havent found much use to it myself, ill be reading up on table functions since i do admit i dont know much about them