Essentially, I have a slider, in which will allow the player to slide from left to right (a scaling system).
However, as seen in the image below, there’s a locked section, so how would I go about stopping the slider from going past the edge of the locked section?
Current code for the slider (apart from the variable lines and whatnot):
local function Snap(number: number, factor: number): number
if factor == 0 then
return number
else
return math.floor(number / factor + 0.5) * factor
end
end
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
debounce = false
end
end)
script.Parent.HeelScaler.Canvas.Bar.Mover.MouseButton1Down:Connect(function()
debounce = true
end)
RunService.RenderStepped:Connect(function()
if debounce then
local mousePos = UserInputService:GetMouseLocation().X
local buttonPos = script.Parent.HeelScaler.Canvas.Bar.Mover.Position
local frameSize = script.Parent.HeelScaler.Canvas.Bar.AbsoluteSize.X
local framePos = script.Parent.HeelScaler.Canvas.Bar.AbsolutePosition.X
local pos = Snap((mousePos - framePos) / frameSize, step)
percentage = math.clamp(pos, 0, 1)
script.Parent.HeelScaler.Canvas.Bar.Mover.Position = UDim2.new(percentage, 0, buttonPos.Y.Scale, buttonPos.Y.Offset)
end
end)
I have currently tried to subtract the size of the locked section off the whole bar itself however, this just led to the slider becoming very off, not aligning with the mouse, and yet, still going over the locked section.
Any help is appreciated!