MouseButton1Click on a Frame Doesn't Work on Mobile

I have a frame that when you click on it (via MouseButton1Click), it will change the active variable, and open a panel.

However, when I switch to a mobile device the clicks don’t register for some reason. I have tried using Enum.UserInputType.Touch but instead of when the frame is tapped, when the frame is being hovered the active variable is set to true and the panel will open.

Whenever the Dynamic Thumbstick sometimes hovers over the frame, the same thing will happen.

How do I make it so the active variable changes when the frame is being tapped and not hovered on mobile?

--this is a localscript
local Frame = script.parent
local active = false
Frame.InputBegan:Connect(
	function(InputObject)
		if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
			if active == true then
				active = false
			elseif active == false then
				active = true
			end
		end
	end
)

I believe a possible workaround could be to turn the frame into a button and then use something like:

local button = script.Parent

button.Activated:Connect(function()

-- do stuff

end)

(I may be wrong tho)

1 Like

I think this will work

local active = false
Frame.InputBegan:Connect(
	function(InputObject)
		local active = false
Frame.InputBegan:Connect(
	function(InputObject)
		if table.find({Enum.UserInputType.MouseButton1,Enum.UserInputType.Touch},input.UserInputType) then
			if active == true then
				active = false
			elseif active == false
				active = true
			end
		end
	end
)
			if active == true then
				active = false
			elseif active == false
				active = true
			end
		end
	end
)

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