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

How to trace the parent of a triggered event?

Asked by
Kervos 15
7 years ago
Edited 7 years ago

So if i were to trigger MouseEnter() on a gui, how would I know which gui that event was fired from, without having to name every single gui? Is there a better way to do this? I am trying to create an inventory gui.

0
Loop through all slots and have an event NexanianStudios 91 — 7y

1 answer

Log in to vote
0
Answered by
Eqicness 255 Moderation Voter
7 years ago
Edited 7 years ago

Use a for loop (iteration)

local inventoryItems = script.Parent.InventoryItems -- Change this to whatever your items are inside.

for i, v in pairs(inventoryItems:GetChildren()) do
   v.MouseEnter:connect(function()
         print("Mouse entered.")
   end)
end)

With this script, v is your GUI and i would be th iterator, or the number of the GUI object in the for loop.

There's most likely a better way to do this, and it might be using UserInputService, I would give you a more detailed answer with info on that but I'm on mobile and it'll take quite a while.

0
Thank you! I was getting very frustrated over this because i was trying to find a way to go around it, but i just didn't know how, this makes it a lot easier. Kervos 15 — 7y
Ad

Answer this question