Advertisement
ERROR_CODE

slider

Nov 24th, 2024 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | None | 0 0
  1. screenGui = Instance.new("ScreenGui")
  2. RFrame = Instance.new("Frame")
  3. RSlider = Instance.new("ImageButton")
  4. valueLabel = Instance.new("TextLabel")
  5. RSliderUICorner = Instance.new("UICorner")
  6. RFrameUICorner = Instance.new("UICorner")
  7. screenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
  8.  
  9. RFrame.Size = UDim2.new(0, 300, 0, 10)
  10. RFrame.Position = UDim2.new(0.5, 0, 0.5, 0)
  11. RFrame.AnchorPoint = Vector2.new(0.5, 0.5)
  12. RFrame.Parent = screenGui
  13. RFrame.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
  14.  
  15. RFrameUICorner.CornerRadius = UDim.new(1, 0)
  16. RFrameUICorner.Parent = RFrame
  17.  
  18. RSlider.Size = UDim2.new(0, 25, 0, 25)
  19. RSlider.Position = UDim2.new(0.035, 0, 0.5, 0)
  20. RSlider.AnchorPoint = Vector2.new(0.5, 0.5)
  21. RSlider.BackgroundColor3 = Color3.fromRGB(66, 170, 255)
  22. RSlider.Parent = RFrame
  23. RSlider.AutoButtonColor = false
  24.  
  25. RSliderUICorner.CornerRadius = UDim.new(1, 0)
  26. RSliderUICorner.Parent = RSlider
  27.  
  28. valueLabel.Size = UDim2.new(0, 50, 0, 50)
  29. valueLabel.Position = UDim2.new(1, 10, 0, 0)
  30. valueLabel.BackgroundColor3 = Color3.new(1, 1, 1)
  31. valueLabel.Text = "0"
  32. valueLabel.Parent = RFrame
  33.  
  34. local function updateSlider_1(input)
  35. local position = math.clamp(input.Position.X - RFrame.AbsolutePosition.X, 0, RFrame.AbsoluteSize.X - RSlider.AbsoluteSize.X)
  36. RSlider.Position = UDim2.new(0, position + RSlider.AbsoluteSize.X / 2, 0.5, 0)
  37. local value = math.floor((position / (RFrame.AbsoluteSize.X - RSlider.AbsoluteSize.X)) * 255)
  38. valueLabel.Text = tostring(value)
  39. end
  40.  
  41. local dragging = false
  42.  
  43. RSlider.InputBegan:Connect(function(input)
  44. if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  45. dragging = true
  46. updateSlider_1(input)
  47. end
  48. end)
  49.  
  50. RSlider.InputEnded:Connect(function(input)
  51. if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  52. dragging = false
  53. end
  54. end)
  55.  
  56. game:GetService("UserInputService").InputChanged:Connect(function(input)if dragging and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then
  57. updateSlider_1(input)
  58. end
  59. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement