HowToRoblox

Button5Script

Jun 22nd, 2020
2,929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1. local btn = script.Parent
  2. local uiGradient = btn:WaitForChild("UIGradient")
  3.  
  4. local isHovering = false
  5.  
  6. local tweenService = game:GetService("TweenService")
  7. local tweenInfo = TweenInfo.new(0.4, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
  8.  
  9. local gradientRemoveTween = tweenService:Create(uiGradient, tweenInfo, {Offset = Vector2.new(-1, 0)})
  10. local gradientRestoreTween = tweenService:Create(uiGradient, tweenInfo, {Offset = Vector2.new(0.4, 0)})
  11.  
  12.  
  13. btn.MouseEnter:Connect(function()
  14.    
  15.     isHovering = true
  16.    
  17.     gradientRemoveTween:Play()
  18. end)
  19.  
  20. btn.MouseLeave:Connect(function()
  21.    
  22.     isHovering = false
  23.    
  24.     gradientRestoreTween:Play()
  25. end)
  26.  
  27. btn.MouseButton1Down:Connect(function()
  28.    
  29.     gradientRestoreTween:Play()
  30. end)
  31.  
  32. btn.MouseButton1Up:Connect(function()
  33.    
  34.     if not isHovering then
  35.         gradientRestoreTween:Play()
  36.     else
  37.         gradientRemoveTween:Play()
  38.     end
  39. end)
Add Comment
Please, Sign In to add comment