Is it possible to make hover and click animations on every text button and image button with 1 script?
like this:
Is it possible to make hover and click animations on every text button and image button with 1 script?
like this:
Hello!
You should do a for in all screen gui instances that are a GuiButton class
Like this:
for _, v in pairs(game:GetService("StarterGui"):GetDescendants()) do
if v:IsA("GuiButton") then
v.MouseEnter:Connect(function()
-- do what tween you want.
end)
v.MouseLeave:Connect(function()
-- resets the tween back.
end)
v.Activated:Connect(function()
-- do what tween you want.
end)
end
end
MouseHover
doesnt exist use MouseEnter
and MouseLeave
Sorry!
I didn’t notice it thank you!
It should be fixed now.
Thank you, does GetChildren() also include the Children of the Child? (because if it doesn’t I don’t think this would work for my case)
Use game:GetService("StarterGui"):GetDescendants()
instead of game:GetService("StarterGui"):GetChildren()
Doesn’t seem to work, I put it into a local script into StarterPlayerScripts
here’s the final code:
for _, v in pairs(game:GetService("StarterGui"):GetDescendants()) do
if v:IsA("GuiButton") then
v.MouseEnter:Connect(function()
v:TweenSize(v.Size * 1.1, Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.25, true)
end)
v.MouseLeave:Connect(function()
v:TweenSize(v.Size / 1.1, Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.25, true)
end)
end
end
Did I do everything correctly?
Made a updated version and still not working even though it seems like it 100% should:
local plr = game.Players.LocalPlayer
for _, v in pairs(plr.PlayerGui.MainGUI:GetDescendants()) do
if v:IsA("TextButton") or v:IsA("ImageButton") then
v.MouseEnter:Connect(function()
local newSize1 = UDim2.new(v.Size.X.Scale * 1.1, v.Size.X.Offset, v.Size.Y.Scale * 1.1, v.Size.Y.Offset)
v:TweenSize(newSize1, Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.25, true)
end)
v.MouseLeave:Connect(function()
local newSize2 = UDim2.new(v.Size.X.Scale / 1.1, v.Size.X.Offset, v.Size.Y.Scale / 1.1, v.Size.Y.Offset)
v:TweenSize(newSize2, Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.25, true)
end)
end
end
If anyone has any ideas please let me know!
Show the Error that you’re getting
OH Wait, I see the issue. Your ImageButtons/TextButtons probably have their Sizes set as offsets. This code will only work on Images with Size set as Scale.
Figured out a way to do this dynamically for no matter offset or Scale (also accounted for variable screensizes)
local plr = game.Players.LocalPlayer
local PlayerGui = plr.PlayerGui
local ScreenSize = PlayerGui:WaitForChild("ScreenGui").AbsoluteSize
for _, v in pairs(plr.PlayerGui:WaitForChild("ScreenGui"):GetDescendants()) do
if v:IsA("TextButton") or v:IsA("ImageButton") then
local originalsize = v.Size
local xAbsoluteSize = (originalsize.X.Scale * ScreenSize.X) + originalsize.X.Offset
local yAbsoluteSize = (originalsize.Y.Scale * ScreenSize.Y) + originalsize.Y.Offset
v.MouseEnter:Connect(function()
local newSize1 = UDim2.new(0,xAbsoluteSize * 1.1,0,yAbsoluteSize*1.1)
v:TweenSize(newSize1, Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.25, true)
end)
v.MouseLeave:Connect(function()
local newSize2 = UDim2.new(0,xAbsoluteSize,0,yAbsoluteSize)
v:TweenSize(newSize2, Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.25, true)
end)
end
end
Thanks for the script, but doesn’t seem to work either
Have you tried this in studio?
Yes i have tried this in studio. Are you sure you’re trying to do this in a local script in StarterPlayerServcies?