Hi, I'm trying to make a vertical UI slider, and it almost works but the slider button slightly shifts to the right every step. Code below v v v
local Slider = script.Parent
local SliderBtn = Slider.Button
local Player = game:GetService("Players").LocalPlayer
local UIS = game:GetService("UserInputService")
local RuS = game:GetService("RunService")
-- Properties
local held = false
local step = 0.2
local percentage = 0
function snap(number, factor)
if factor == 0 then
return number
else
return math.floor(number/factor+0.5)*factor
end
end
UIS.InputEnded:connect(function(input, processed)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
held = false
end
end)
script.Parent.Button.TextButton.MouseButton1Down:Connect(function()
held = true
end)
RuS.RenderStepped:connect(function(delta)
if held then
local MousePos = UIS:GetMouseLocation().Y
local BtnPos = SliderBtn.Position
local SliderSize = Slider.AbsoluteSize.Y
local SliderPos = Slider.AbsolutePosition.Y
local pos = snap((MousePos-SliderPos)/SliderSize,step)
percentage = math.clamp(pos,0,1)
SliderBtn.Position = UDim2.new(percentage,0,BtnPos.X.Scale, BtnPos.X.Offset)
end
end)
