Facebook
From SpacialEthanRB, 3 Years ago, written in Lua.
Embed
Download Paste or View Raw
Hits: 227
  1. local TweenService = game:GetService("TweenService")
  2.  
  3. local AnimateObject = {}
  4. AnimateObject.__index = AnimateObject
  5.  
  6. local AnimateStyles = {
  7.         Hover = {
  8.                 ["Grow"] = function(Object, ChangeAmount)
  9.                         local OriginalSize = Object.Size
  10.                         local Amount = ChangeAmount or 0.01
  11.  
  12.                         Object.MouseEnter:Connect(function()
  13.                                 Object:TweenSize(
  14.                                         UDim2.new(Object.Size.X.Scale + Amount, 0, Object.Size.Y.Scale + Amount, 0),
  15.                                         "In",
  16.                                         "Quad",
  17.                                         0.1,
  18.                                         true
  19.                                 )
  20.                         end)
  21.  
  22.                         Object.MouseLeave:Connect(function()
  23.                                 Object:TweenSize(OriginalSize, "In", "Quad", 0.1, true)
  24.                         end)
  25.  
  26.                 end;
  27.  
  28.                 ["Shrink"] = function(Object, ChangeAmount)
  29.                         local OriginalSize = Object.Size
  30.                         local Amount = ChangeAmount or 0.01
  31.  
  32.                         Object.MouseEnter:Connect(function()
  33.                                 Object:TweenSize(
  34.                                         UDim2.new(Object.Size.X.Scale - Amount, 0, Object.Size.Y.Scale - Amount, 0),
  35.                                         "In",
  36.                                         "Quad",
  37.                                         0.1,
  38.                                         true
  39.                                 )
  40.                         end)
  41.  
  42.                         Object.MouseLeave:Connect(function()
  43.                                 Object:TweenSize(OriginalSize, "In", "Quad", 0.1, true)
  44.                         end)
  45.  
  46.                 end;
  47.  
  48.                 ["TextColor"] = function(Object, NewColor)
  49.                         local OriginalColor = Object.TextColor3
  50.                         local Color = NewColor or Color3.fromRGB(0, 255, 0)
  51.  
  52.                         Object.MouseEnter:Connect(function()
  53.                                 Object.TextColor3 = Color
  54.                         end)
  55.  
  56.                         Object.MouseLeave:Connect(function()
  57.                                 Object.TextColor3 = OriginalColor
  58.                         end)
  59.                 end;
  60.  
  61.                 ["BackgroundColor"] = function(Object, NewColor)
  62.                         local OriginalColor = Object.BackgroundColor3
  63.                         local Color = NewColor or Color3.fromRGB(0, 255, 0)
  64.  
  65.                         Object.MouseEnter:Connect(function()
  66.                                 Object.BackgroundColor3 = Color
  67.                         end)
  68.  
  69.                         Object.MouseLeave:Connect(function()
  70.                                 Object.BackgroundColor3 = OriginalColor
  71.                         end)
  72.                 end;
  73.                
  74.                 ["Rotate"] = function(Object, RotationAmount)
  75.                         --I will start by making a few variables:
  76.                         local OriginalRotation = Object.Rotation
  77.  
  78.                         Object.MouseEnter:Connect(function()
  79.                                 TweenService:Create(Object,
  80.                                         TweenInfo.new(0.1,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0),
  81.                                         {Rotation = RotationAmount}
  82.                                 ):Play()
  83.                         end)
  84.  
  85.                         Object.MouseLeave:Connect(function()
  86.                                 TweenService:Create(Object,
  87.                                         TweenInfo.new(0.1,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0),
  88.                                         {Rotation = OriginalRotation}
  89.                                 ):Play()
  90.                         end)
  91.                 end;
  92.         };
  93.        
  94.         LeftClick = {
  95.                 ["BackgroundColor"] = function(Object, NewColor)
  96.                         local OriginalColor = Object.BackgroundColor3
  97.                         local Color = NewColor or Color3.fromRGB(0, 255, 0)
  98.  
  99.                         Object.MouseButton1Down:Connect(function()
  100.                                 Object.BackgroundColor3 = Color
  101.                         end)
  102.  
  103.                         Object.MouseButton1Up:Connect(function()
  104.                                 Object.BackgroundColor3 = OriginalColor
  105.                         end)
  106.                 end;
  107.                
  108.                 ["Grow"] = function(Object, ChangeAmount)
  109.                         local OriginalSize = Object.Size
  110.                         local Amount = ChangeAmount or 0.01
  111.  
  112.                         Object.MouseButton1Down:Connect(function()
  113.                                 Object:TweenSize(
  114.                                         UDim2.new(Object.Size.X.Scale + Amount, 0, Object.Size.Y.Scale + Amount, 0),
  115.                                         "In",
  116.                                         "Quad",
  117.                                         0.1,
  118.                                         true
  119.                                 )
  120.                         end)
  121.  
  122.                         Object.MouseButton1Up:Connect(function()
  123.                                 Object:TweenSize(OriginalSize, "In", "Quad", 0.1, true)
  124.                         end)
  125.  
  126.                 end;
  127.  
  128.                 ["Shrink"] = function(Object, ChangeAmount)
  129.                         local OriginalSize = Object.Size
  130.                         local Amount = ChangeAmount or 0.01
  131.  
  132.                         Object.MouseButton1Down:Connect(function()
  133.                                 Object:TweenSize(
  134.                                         UDim2.new(Object.Size.X.Scale - Amount, 0, Object.Size.Y.Scale - Amount, 0),
  135.                                         "In",
  136.                                         "Quad",
  137.                                         0.1,
  138.                                         true
  139.                                 )
  140.                         end)
  141.  
  142.                         Object.MouseButton1Up:Connect(function()
  143.                                 Object:TweenSize(OriginalSize, "In", "Quad", 0.1, true)
  144.                         end)
  145.  
  146.                 end;
  147.                
  148.                
  149.         };
  150.        
  151.         RighClick = {
  152.                 ["BackgroundColor"] = function(Object, NewColor)
  153.                         local OriginalColor = Object.BackgroundColor3
  154.                         local Color = NewColor or Color3.fromRGB(0, 255, 0)
  155.  
  156.                         Object.MouseButton2Down:Connect(function()
  157.                                 Object.BackgroundColor3 = Color
  158.                         end)
  159.  
  160.                         Object.MouseButton2Up:Connect(function()
  161.                                 Object.BackgroundColor3 = OriginalColor
  162.                         end)
  163.                 end;
  164.                
  165.                 ["Grow"] = function(Object, ChangeAmount)
  166.                         local OriginalSize = Object.Size
  167.                         local Amount = ChangeAmount or 0.01
  168.  
  169.                         Object.MouseButton2Down:Connect(function()
  170.                                 Object:TweenSize(
  171.                                         UDim2.new(Object.Size.X.Scale + Amount, 0, Object.Size.Y.Scale + Amount, 0),
  172.                                         "In",
  173.                                         "Quad",
  174.                                         0.1,
  175.                                         true
  176.                                 )
  177.                         end)
  178.  
  179.                         Object.MouseButton2Up:Connect(function()
  180.                                 Object:TweenSize(OriginalSize, "In", "Quad", 0.1, true)
  181.                         end)
  182.  
  183.                 end;
  184.  
  185.                 ["Shrink"] = function(Object, ChangeAmount)
  186.                         local OriginalSize = Object.Size
  187.                         local Amount = ChangeAmount or 0.01
  188.  
  189.                         Object.MouseButton2Down:Connect(function()
  190.                                 Object:TweenSize(
  191.                                         UDim2.new(Object.Size.X.Scale - Amount, 0, Object.Size.Y.Scale - Amount, 0),
  192.                                         "In",
  193.                                         "Quad",
  194.                                         0.1,
  195.                                         true
  196.                                 )
  197.                         end)
  198.  
  199.                         Object.MouseButton2Up:Connect(function()
  200.                                 Object:TweenSize(OriginalSize, "In", "Quad", 0.1, true)
  201.                         end)
  202.  
  203.                 end;
  204.                
  205.         };
  206.        
  207. }
  208.  
  209.  
  210. function AnimateObject.new(Object)
  211.         local self = setmetatable({}, AnimateObject)
  212.        
  213.         self.Object = Object
  214.  
  215.         return Object, self
  216. end
  217.  
  218. function AnimateObject:Configuire(Action, Style, Change)
  219.         local Object = self.Object
  220.        
  221.         local ChosenTween = AnimateStyles[Action][Style]
  222.         ChosenTween(Object, Change)
  223. end
  224.  
  225.  
  226. return AnimateObject
captcha