HowToRoblox

Button8Script

Jun 22nd, 2020
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 KB | None | 0 0
  1. local btn = script.Parent
  2. local btnText = btn:WaitForChild("BtnText")
  3.  
  4. local btnHoverArea = btn.Parent
  5.  
  6. local lineTop = btnHoverArea:WaitForChild("LineTop")
  7. local lineBottom = btnHoverArea:WaitForChild("LineBottom")
  8.  
  9. local isHovering = false
  10.  
  11. local tweenService = game:GetService("TweenService")
  12. local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
  13.  
  14. local btnSizeInTween = tweenService:Create(btn, tweenInfo, {Size = UDim2.new(0.001, 0, 1, 0), ImageTransparency = 1})
  15. local btnSizeOutTween = tweenService:Create(btn, tweenInfo, {Size = UDim2.new(1, 0, 1, 0), ImageTransparency = 0})
  16.  
  17. local textTransparentTween = tweenService:Create(btnText, tweenInfo, {TextTransparency = 1})
  18. local textOpaqueTween = tweenService:Create(btnText, tweenInfo, {TextTransparency = 0})
  19.  
  20. local bottomLineTweenOut = tweenService:Create(lineBottom, tweenInfo, {Size = UDim2.new(1, 0, 0, 1), BackgroundTransparency = 0})
  21. local bottomLineTweenIn = tweenService:Create(lineBottom, tweenInfo, {Size = UDim2.new(0, 0, 0, 1), BackgroundTransparency = 1})
  22. local topLineTweenOut = tweenService:Create(lineTop, tweenInfo, {Size = UDim2.new(1, 0, 0, 1), BackgroundTransparency = 0})
  23. local topLineTweenIn = tweenService:Create(lineTop, tweenInfo, {Size = UDim2.new(0, 0, 0, 1), BackgroundTransparency = 1})
  24.  
  25.  
  26. local function hoverTween()
  27.    
  28.     btnSizeOutTween:Cancel()
  29.     textOpaqueTween:Cancel()
  30.     bottomLineTweenIn:Cancel()
  31.     topLineTweenIn:Cancel()
  32.    
  33.     btnSizeInTween:Play()
  34.     textTransparentTween:Play()
  35.     bottomLineTweenOut:Play()
  36.     topLineTweenOut:Play()
  37. end
  38.  
  39. local function hoverTweenReverse()
  40.  
  41.     btnSizeInTween:Cancel()
  42.     textTransparentTween:Cancel()
  43.     bottomLineTweenOut:Cancel()
  44.     topLineTweenOut:Cancel()
  45.    
  46.     btnSizeOutTween:Play()
  47.     textOpaqueTween:Play()
  48.     bottomLineTweenIn:Play()
  49.     topLineTweenIn:Play()
  50. end
  51.  
  52.  
  53. btnHoverArea.MouseEnter:Connect(function()
  54.    
  55.     isHovering = true
  56.    
  57.     hoverTween()
  58. end)
  59.  
  60. btnHoverArea.MouseLeave:Connect(function()
  61.    
  62.     isHovering = false
  63.    
  64.     hoverTweenReverse()
  65. end)
  66.  
  67. btnHoverArea.MouseButton1Down:Connect(function()
  68.    
  69.     hoverTweenReverse()
  70. end)
  71.  
  72. btnHoverArea.MouseButton1Up:Connect(function()
  73.    
  74.     if not isHovering then
  75.         hoverTweenReverse()
  76.     else
  77.         hoverTween()
  78.     end
  79. end)
Add Comment
Please, Sign In to add comment