What do I want to do?
I would to like to enlarge a gui button when I hover my mouse over and undo the size after my mouse stops hovering
I know I need to use MouseEnter event but how to enlarge? Tween or just multiple the size by like 0.3
What do I want to do?
I would to like to enlarge a gui button when I hover my mouse over and undo the size after my mouse stops hovering
I know I need to use MouseEnter event but how to enlarge? Tween or just multiple the size by like 0.3
If you want it to be smooth then use tween, here’s an example:
LocalScript inside the button:
local ogSize = script.Parent.Size
local duration = 1
script.Parent.MouseEnter:Connect(function()
script.Parent:TweenSize(ogSize + UDim2.new(0.1,0,0.1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, duration)
end)
script.Parent.MouseLeave:Connect(function()
script.Parent:TweenSize(ogSize, Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, duration)
end)
local Enumeration = Enum
local Game = game
local TweenService = Game:GetService("TweenService")
local Script = script
local GuiObject = Script.Parent
local Tween
local function OnMouseEnter()
if Tween then Tween:Cancel() end
Tween = TweenService:Create(GuiObject, TweenInfo.new(1, Enumeration.EasingStyle.Linear, Enumeration.EasingDirection.Out), {Size = UDim2.new()}) --Make the gui object's size bigger.
Tween:Play()
end
local function OnMouseLeave()
if Tween then Tween:Cancel() end
Tween = TweenService:Create(GuiObject, TweenInfo.new(1, Enumeration.EasingStyle.Linear, Enumeration.EasingDirection.Out), {Size = UDim2.new()}) --Revert gui object's size back to normal.
Tween:Play()
end
GuiObject.MouseEnter:Connect(OnMouseEnter)
GuiObject.MouseLeave:Connect(OnMouseLeave)
You’ll need to specify the sizes and/or other tween properties.
How would I make it slightly tilt aswell? Also, my textButton has text, and it just scales the text up instead of the button itself
You could add rotation to tilt this, and could you elaborate on the “Also, my textButton has text, and it just scales the text up instead of the button itself”
local ogSize = script.Parent.Size
local duration = 1
script.Parent.MouseEnter:Connect(function()
script.Parent:TweenSize(ogSize + UDim2.new(0.1,0,0.1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, duration)
script.Parent.Rotation = 5 -- change this however you want
end)
script.Parent.MouseLeave:Connect(function()
script.Parent:TweenSize(ogSize, Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, duration)
script.Parent.Rotation = 0
end)