Advertisement
ERROR_CODE

gradient animated

Nov 16th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local playerGui = player:WaitForChild("PlayerGui")
  3.  
  4. local screenGui = Instance.new("ScreenGui")
  5. screenGui.Parent = playerGui
  6.  
  7. local button = Instance.new("TextButton")
  8. button.Size = UDim2.new(0, 200, 0, 200)
  9. button.Position = UDim2.new(0.5, -100, 0.5, -25)
  10. button.Text = "Hover Me"
  11. button.Parent = screenGui
  12.  
  13. local gradient = Instance.new("UIGradient")
  14. gradient.Color = ColorSequence.new{
  15.     ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 0, 0)),
  16.     ColorSequenceKeypoint.new(0.4, Color3.fromRGB(255, 0, 0)),
  17.     ColorSequenceKeypoint.new(0.6, Color3.fromRGB(0, 0, 255)),
  18.     ColorSequenceKeypoint.new(1, Color3.fromRGB(0, 0, 255))
  19. }
  20. gradient.Parent = button
  21.  
  22. local TweenService = game:GetService("TweenService")
  23.  
  24. local function createTween(object, properties, duration)
  25.     local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
  26.     local tween = TweenService:Create(object, tweenInfo, properties)
  27.     return tween
  28. end
  29.  
  30. local isHovering = false
  31.  
  32. button.MouseEnter:Connect(function()
  33.     isHovering = true
  34.     local tween = createTween(gradient, {Rotation = 180}, 1)
  35.     tween:Play()
  36. end)
  37.  
  38. button.MouseLeave:Connect(function()
  39.     isHovering = false
  40.     local tween = createTween(gradient, {Rotation = 0}, 1)
  41.     tween:Play()
  42. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement