local script in the button:
local uimodule = require(game.ReplicatedStorage.UiModule)
uimodule.Animate(script.Parent)
script.Parent.MouseButton1Down:Connect(function()
uimodule.ToggleFrame(script.Parent.Parent.Frame)
end)
module script in replicatestorage:
local tweenService = game:GetService("TweenService")
local enterMulti = 1.1
local downMulti = 0.8
local hoverSound = script.hoverSound
local clickSound = script.clickSound
local AnimationModule = {}
local function enter(Button, size)
tweenService:Create(Button, TweenInfo.new(.1), {Size = UDim2.new(size.X.Scale * enterMulti, size.X.Offset, size.Y.Scale * enterMulti, size.Y.Offset)}):Play()
hoverSound:Play()
end
local function leave(Button, size)
tweenService:Create(Button, TweenInfo.new(.1), {Size = size}):Play()
end
local function down(Button, size)
tweenService:Create(Button, TweenInfo.new(.1), {Size = UDim2.new(size.X.Scale * downMulti, size.X.Offset, size.Y.Scale * downMulti, size.Y.Offset)}):Play()
end
local function up(Button, size)
tweenService:Create(Button, TweenInfo.new(.1), {Size = UDim2.new(size.X.Scale * enterMulti, size.X.Offset, size.Y.Scale * enterMulti, size.Y.Offset)}):Play()
clickSound:Play()
end
AnimationModule.Animate = function(Button)
if Button:IsA("GuiButton") then
local size = Button.Size
Button.MouseEnter:Connect(function()
enter(Button, size)
end)
Button.MouseLeave:Connect(function()
leave(Button, size)
end)
Button.MouseButton1Down:Connect(function()
down(Button, size)
end)
Button.MouseButton1Up:Connect(function()
up(Button, size)
end)
end
end
AnimationModule.ToggleFrame = function(Frame)
local position = Frame.Position
if Frame:IsA("Frame") then
if Frame.Visible == false then
Frame.Position = UDim2.new(position.X.Scale, position.X.Offset, position.Y.Scale + 0.1, position.Y.Offset)
Frame.Visible = true
tweenService:Create(Frame, TweenInfo.new(.25, Enum.EasingStyle.Bounce), {Position = position}):Play()
else
Frame.Visible = false
end
end
end
return AnimationModule
Problem:
It does not animate the button when mouseenter/mouseleave/mousebuttondown/mousebuttonup
Video: