I made a slider gui following a tutorial, the problem is the “step” relies on a number like 0.01, but I want to make it an increment.
For example, if it were a fov value, the max value would be 120, and the min value would be 50, and the increment/step could be 1 so that’s how much it increases by when sliding. The problem is I don’t know how to implement this
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local sliderButton = script.Parent
local sliderFrame = sliderButton.Parent
local sliding = false
local function snap(number, factor)
if factor == 0 then
return number
else
return math.floor(number/factor + 0.5) * factor
end
end
UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then
return
end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
sliding = false
end
end)
script.Parent.MouseButton1Down:Connect(function()
sliding = true
end)
RunService.PreRender:Connect(function()
if sliding then
local mousePosition = UserInputService:GetMouseLocation().X
local sliderPosition = sliderButton.Position
local frameSize = sliderFrame.AbsoluteSize.X
local framePosition = sliderFrame.AbsolutePosition.X
local position = snap((mousePosition - framePosition)/frameSize, 0.01)
local percentage = math.clamp(position, 0, 1)
sliderButton.Position = UDim2.new(percentage, 0, sliderPosition.Y.Scale, sliderPosition.Y.Offset)
end
end)