Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Give multiple buttons same function?

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.

1 comment

0

you use MouseEnter and MouseLeave in the for loop ( v.MouseEnter:Connect(function() glow up end) )

1 answer

✓ Accepted answer

###You're on the right track. All you need to do is connect a function to the 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

1 comment

0

Thank you so much!

This discussion is preserved as it was. New answers, comments, and votes are closed.