How would I connect the looped button at the bottom of this post, to the “.MouseEnter” event?
I tried this and it works. I am not sure if it is efficient, nor a good practice of doing that though.
for _,button in pairs(client.MainButtons:GetChildren()) do
if button:IsA("ImageButton") then
button.MouseEnter:Connect(function(x, y)
print("Entered!")
end)
end
end
I think it would be better to connect the buttons/event, but how?
for _,button in pairs(client.MainButtons:GetChildren()) do
if button:IsA("ImageButton") then
-- connect button to GuiObject below somehow.
end
end
GuiObject.MouseEnter:Connect(function(x, y)
-- connect to "button" above.
-- run a function...
end)
Not sure if that’s what you mean, but if you don’t care about knowing which button was entered, you can make a single function instead of creating one every time
local function OnMouseEnter(x, y)
print("im now a happy button")
end
for _,button in pairs(client.MainButtons:GetChildren()) do
if button:IsA("ImageButton") then
button.MouseEnter:Connect(OnMouseEnter)
end
end
The former method is fine. I don’t think there’s a reason to link it. It would probably just complicate it unless you’re using the same block multiple times, then in that case you should wrap it in a function.
hth!