Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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.

0
You could use the script in conjunction with the Mouse Button1Down event. M39a9am3R 3210 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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)
Ad
Log in to vote
1
Answered by 9 years ago

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.

Answer this question