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

How to get a reference to the GUI element that was interacted with?

Asked by 5 years ago

I have a frame which has a left and a right frame within (or image/button.)

I'm trying to connect the children frames to a function which in turn needs to reference the frame called the function. The input parameter only provides information about the delta, keycode, position, user input state and type.

Is there any way to find out which frame was clicked? (Other than having to compute it using the coordinates of each frame?)

local parentFrame = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame
local leftFrame = parentFrame.LeftFrame
local rightFrame = parentFrame.RightFrame

local function foo(input)
    --how can I get the frame that was interacted with in here?
    --local clickedFrame = ???

    --code goes here...
end

leftFrame.InputBegan:Connect(foo)
rightFrame.InputBegan:Connect(foo)

1 answer

Log in to vote
1
Answered by 5 years ago
local parentFrame = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame
local leftFrame = parentFrame.LeftFrame
local rightFrame = parentFrame.RightFrame

local function foo(input, frame)
    --how can I get the frame that was interacted with in here?
    --local clickedFrame = frame

    --code goes here...
end

leftFrame.InputBegan:Connect(function(input)
    foo(input, leftFrame)
    -- or just do foo code here idk
end)
rightFrame.InputBegan:Connect(function(input)
    foo(input, rightFrame)  
    -- or just do foo code here idk
end)
Ad

Answer this question