Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is it possible to detect if a GUI Frame is clicked without a button?

My script:

script.Parent.Visible = true
player = game.Players.LocalPlayer
mouse = player:GetMouse()
down = false

top = false
bottom = false

script.Parent.Changed:connect(function(value)
	if value == "Position" then
		while down == true and wait() do
			local posY = script.Parent.Position.Y.Offset
			print("DownLoop "..posY)
			if posY < -400 then
				top = true
				print("Top = true")
			elseif posY > 200 then
				down = true
				print("Down = true")
			end
			
			if top == true and down == true then
				print("Both = true")
				script.Parent.Visible = false
				script.Disabled = false
			end
		end
	end
end)

mouse.Button1Down:connect(function()
	down = true
	print("Down")
end)

mouse.Button1Up:connect(function()
	print("Up")
	down = false
	top = false
	bottom = false
end)

When I click the frame the Button1Down event is not fired.

1 comment

0

You could use the script in conjunction with the Mouse Button1Down event.

2 answers

✓ Accepted answer

You can use this, it work with the input as opposed to a mouse event:-

local mouseClick = nil

script.Parent.InputBegan:connect(function (inp)
	if inp.UserInputType.Value == 0 then --This is the key code for mouse 1 
		mouseClick = true --down
	end
end)

--Mouse is up
script.Parent.InputEnded:connect(function (inp)
	if inp.UserInputType.Value == 0 then -- This is the key code for mouse 1 
		mouseClick = false -- up
	end
end)

I guess it would be possible with the new UserInputService.

To get the mouse when it's down you would have to use this:

function MouseDown(input,gameProcessedEvent )
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		--code	
	end
end

game:GetService("UserInputService").InputBegan:connect(MouseDown)

For mouse up:

function MouseUp(input,gameProcessedEvent )
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		--code	
	end
end

game:GetService("UserInputService").InputEnded:connect(MouseUp)

The issue with this is that this will constantly detect when the mouse is down. I would just recommend you stick with a TextButton and set it to be invisible.

This discussion is preserved as it was. New answers, comments, and votes are closed.