Video of the animation: https://streamable.com/rj7zkn
local TweenService = game:GetService("TweenService")
local frame = script.Parent
local one = script.Parent.one
local two = script.Parent.two
local three = script.Parent.three
local Shop = script.Parent.Shop
--mouse leave variables
local ogSize = UDim2.fromScale(0.75, 0.166)
local ogPos = UDim2.fromScale(0.12, 0.205)
local ogPos2 = UDim2.new(0.12, 0,0.417, 0)
local ogPos3 = UDim2.new(0.12, 0,0.639, 0)
--info
local tweenInfoRotation = TweenInfo.new(
0.1,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local goalRotation = {
Rotation = 20
}
local goalSizePosition = {
Size = UDim2.new(0.56, 0, 0.11, 0),
Position = UDim2.new(0.21, 0 ,0.261, 0)
}
local goalSizePosition2 = {
Size = UDim2.new(0.56, 0, 0.11, 0),
Position = UDim2.new(0.21, 0,0.441, 0)
}
local goalSizePosition3 = {
Size = UDim2.new(0.56, 0, 0.11, 0),
Position = UDim2.new(0.21, 0,0.641, 0)
}
local tweenInfoSizePosition = TweenInfo.new(
0.1,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local tweenInfoShop = TweenInfo.new(
0.3,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
0
)
local shopNewPos = UDim2.new(-7, 0, -0.001, 0)
local shopOgPos = UDim2.new(1.2, 0, -0.001, 0)
local tweenEnterShop = TweenService:Create(Shop, tweenInfoShop, {Position = shopNewPos})
local tweenLeaveShop = TweenService:Create(Shop, tweenInfoShop, {Position = shopOgPos})
--one
local tweenEnterRotation = TweenService:Create(one, tweenInfoRotation, goalRotation)
local tweenEnterSizePosition = TweenService:Create(one, tweenInfoSizePosition, goalSizePosition)
local tweenLeaveSizePos = TweenService:Create(one, tweenInfoRotation, {Size = ogSize, Position = ogPos})
local tweenLeaveRotation = TweenService:Create(one, tweenInfoRotation, {Rotation = 0})
frame.one.MouseEnter:Connect(function()
tweenEnterRotation:Play()
tweenEnterSizePosition:Play()
end)
frame.one.MouseLeave:Connect(function()
tweenLeaveSizePos:Play()
tweenLeaveRotation:Play()
end)
--two
local tweenEnterRotation2 = TweenService:Create(two, tweenInfoRotation, goalRotation)
local tweenEnterSizePosition2 = TweenService:Create(two, tweenInfoSizePosition, goalSizePosition2)
local tweenLeaveSizePos2 = TweenService:Create(two, tweenInfoRotation, {Size = ogSize, Position = ogPos2})
local tweenLeaveRotation2 = TweenService:Create(two, tweenInfoRotation, {Rotation = 0})
frame.two.MouseEnter:Connect(function()
tweenEnterRotation2:Play()
tweenEnterSizePosition2:Play()
end)
frame.two.MouseLeave:Connect(function()
tweenLeaveSizePos2:Play()
tweenLeaveRotation2:Play()
end)
--three
local tweenEnterRotation3 = TweenService:Create(three, tweenInfoRotation, goalRotation)
local tweenEnterSizePosition3 = TweenService:Create(three, tweenInfoSizePosition, goalSizePosition3)
local tweenLeaveSizePos3 = TweenService:Create(three, tweenInfoRotation, {Size = ogSize, Position = ogPos3})
local tweenLeaveRotation3 = TweenService:Create(three, tweenInfoRotation, {Rotation = 0})
frame.three.MouseEnter:Connect(function()
tweenEnterRotation3:Play()
tweenEnterSizePosition3:Play()
end)
frame.three.MouseLeave:Connect(function()
tweenLeaveSizePos3:Play()
tweenLeaveRotation3:Play()
end)
--Shop
local isShopOpen = false
one.MouseButton1Up:Connect(function()
if isShopOpen == false then
tweenEnterShop:Play()
isShopOpen = true
else
tweenLeaveShop:Play()
isShopOpen = false
end
end)

7 comments
Thank you so much for this post, I agree with your method of simplification but I'm confused about one thing. On line 41 of the last code block you posted, the handleTweening function requires the argument "ENTERPROPERTIES" and "LEAVEPROPERTIES". What would I put here? Aren't the properties already defined in the individual functions? And on line 20, you create a tween with 3 parameters...
...but on line 26 you use three arguments. I REALLY like this answer, but I'm having a hard time wrapping my head around it because since theres a lot of variables. Thank you again
I understand your confusion. The ENTERPROPERTIES defines how properties (Size, Position, Rotation) should change when the mouse enters the gui. So you would enter the tween's properties as the argument. IE: {Size = UDim.new(Values here), Position = UDim.new(Values here), Rotation = (Put rotation here)}
And LEAVEPROPERTIES is the same thing but for when the mouse leaves the GUI
So in full it would look something like this: handleTweening(Your gui object,{Size = UDim.new(Enter size here), Position = UDim.new(Enter position here), Rotation = (Enter rotation here)},{Size = UDim.new(Leave size here), Position = UDim.new(Leave position here), Rotation = (Put Leave rotation here)})
And as for using two arguments; we don't really need to create a new TweenInfo everytime we call the function, because most of the time you only want the position, size, and rotation of the object to change. Because we don't need to change the tweenInfo over each GUI object we can simply write the tweenInfo inside the function, so that the tweenInfo would be same for all objects.
If anyone on the internet needs this, know that the part in MouseLeave/MouseEnter, the properties table will cause an error and should be deleted.