You would definitely need some bounds for how far the slider would go. A simple math.clamp would be enough for this, but figuring out these bounds are hard, as well as the placing of the slider:
local originalPos = fr.Position
local slider = --slider gui
local padding = --number of pixels off the edges
local leftBound = padding
local rightBound = slider.AbsoluteSize.X - padding
mouse.Move:Connect(function()
if down == true then
fr.Position = UDim2.new(
UDim.new(0, math.clamp(
mouse.X - slider.AbsolutePosition.X,
leftBound, rightBound
)),
originalPos.Y
)
end
end)
There is a very good chance that my math is off and it errors. Please document its behavior as clearly as possible if it is not intended!
My guess is you have it inside some gui object that has its own nonzero X position, and you’re setting the position relative to the container. Subtract the position of the container from the mouse position.
You’ll be dealing with AbsolutePosition and AbsoluteSize for Math stuff most of the time so use that instead of Offset and Scale also use events like InputBegan and such