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 6 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?)

01local parentFrame = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame
02local leftFrame = parentFrame.LeftFrame
03local rightFrame = parentFrame.RightFrame
04 
05local function foo(input)
06    --how can I get the frame that was interacted with in here?
07    --local clickedFrame = ???
08 
09    --code goes here...
10end
11 
12leftFrame.InputBegan:Connect(foo)
13rightFrame.InputBegan:Connect(foo)

1 answer

Log in to vote
1
Answered by 6 years ago
01local parentFrame = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame
02local leftFrame = parentFrame.LeftFrame
03local rightFrame = parentFrame.RightFrame
04 
05local function foo(input, frame)
06    --how can I get the frame that was interacted with in here?
07    --local clickedFrame = frame
08 
09    --code goes here...
10end
11 
12leftFrame.InputBegan:Connect(function(input)
13    foo(input, leftFrame)
14    -- or just do foo code here idk
15end)
16rightFrame.InputBegan:Connect(function(input)
17    foo(input, rightFrame) 
18    -- or just do foo code here idk
19end)
Ad

Answer this question