I want the GUI buttons change size when the mouse hovers over them. This is achieved with MouseEnter and MouseLeave as shown in the script:
REMOVED
I’ve put print statements for everything, and they all worked, except the ones that should print when Mouse enter/leave functions connect. This means the script doesn’t detect the mouse entering/leaving the button.
I tried this local script with specific buttons, placing the local script as a child inside these buttons and they worked, but when I try to make it work for ALL buttons in my game, it won’t. How can I achieve this?
You’re using the buttons in StarterGui, not PlayerGui.
local player = game:GetService("Players").LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
task.wait(5) --give buttons some time to load (only used as example here)
for _, button in next, playerGui:GetDescendants(), nil do
if v:IsA("TextButton") or v:IsA("ImageButton") then
local startsize = v.Size
local hoversize = UDim2.new(v.Size.Width.Scale * 1.05, 0, v.Size.Height.Scale * 2, 0)
v.MouseEnter:Connect(function()
v:TweenSize(hoversize,Enum.EasingDirection.Out,Enum.EasingStyle.Sine,.25,true)
end)
v.MouseLeave:Connect(function()
v:TweenSize(startsize,Enum.EasingDirection.Out,Enum.EasingStyle.Sine,.25,true)
end)
end
end