I've been working on an inventory GUI, so far so good but I dont quite understand how I give multiple buttons the same function. I want all buttons to have a glow effect when the player's mouse hovers over them. I know I could give them the function individually but I feel thats not efficient.
local items = { item1 = itemselect.Item1, item2 = itemselect.Item2, item3 = itemselect.Item3, item4 = itemselect.Item4, item5 = itemselect.Item5, item6 = itemselect.Item6, item7 = itemselect.Item7, item8 = itemselect.Item8, } for i,v in pairs(items) do print(i,v) end
I was told to use a for i,v pair loop but this still doesn't answer my question.
MouseHover
event for each button.local items = { item1 = itemselect.Item1, item2 = itemselect.Item2, item3 = itemselect.Item3, item4 = itemselect.Item4, item5 = itemselect.Item5, item6 = itemselect.Item6, item7 = itemselect.Item7, item8 = itemselect.Item8, } for _, v in pairs(items) do -- loop through each item v.MouseHover:Connect(function()--connect a function to the mousehover event for each item -- do something ......…… end) end