Advertisement
HowToRoblox

ButtonEffect

Dec 7th, 2020
2,197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.36 KB | None | 0 0
  1. local button = script.Parent:WaitForChild("Button")
  2. local shadow = script.Parent:WaitForChild("ButtonShadow")
  3.  
  4. local glow = button:WaitForChild("Glow")
  5. glow.ImageTransparency = 1
  6.  
  7.  
  8. local originalPos = button.Position
  9. local buttonOffset = button.Position.Y.Scale - shadow.Position.Y.Scale
  10.  
  11.  
  12. local tweenService = game:GetService("TweenService")
  13. local glowTI = TweenInfo.new(0.5, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
  14.  
  15.  
  16. button.MouseEnter:Connect(function()
  17.    
  18.     local btnPosition = button.Position - UDim2.new(0, 0, buttonOffset/2, 0)
  19.    
  20.     button:TweenPosition(btnPosition, "InOut", "Quint", 0.25, true)
  21.    
  22.     script.HoverSound:Play()
  23. end)
  24.  
  25. button.MouseLeave:Connect(function()
  26.  
  27.     button:TweenPosition(originalPos, "Out", "Bounce", 0.25, true)
  28.    
  29.     local glowTween = tweenService:Create(glow, glowTI, {ImageTransparency = 1})
  30.     glowTween:Play()
  31. end)
  32.  
  33.  
  34. button.MouseButton1Down:Connect(function()
  35.  
  36.     button:TweenPosition(shadow.Position, "InOut", "Quint", 0.5, true)
  37.        
  38.     local glowTween = tweenService:Create(glow, glowTI, {ImageTransparency = 0})
  39.     glowTween:Play()
  40.    
  41.     script.ButtonPress:Play()
  42. end)
  43.  
  44.  
  45. button.MouseButton1Up:Connect(function()
  46.    
  47.     button:TweenPosition(originalPos, "Out", "Bounce", 0.25, true)
  48.    
  49.     local glowTween = tweenService:Create(glow, glowTI, {ImageTransparency = 1})
  50.     glowTween:Play()
  51.    
  52.     script.ButtonRelease:Play()
  53. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement