I have a slider that for some reason bottoms out at 0.025 and tops out at 0.975 (Position.X.Scale) I’d like it to go all the way to 0 and 1. Not sure how to do it, I’m here for help and suggestions.
Slider.rbxl (61.7 KB) ← here is a simplified file with only the problematic item
Press play, it should print the slider’s position whenever you drag it.
Thank you for this code, but it’s not what I was looking for. I’m looking for the slider to be able to reach the expected limits, not a workaround. Thanks again :D
The handle can’t fully reach the edges because of its own Size. The Position.X.Scale is relative to the top-left of the handle, not the center of the slider track. To hit 0 to 1 you need to account for the handle size:
local Handle = script.Parent.SliderContainer.Handle
local Track = script.Parent.SliderContainer
local preciseness = 4
local num = 10^preciseness
Handle:GetPropertyChangedSignal("Position"):Connect(function()
local trackWidth = Track.AbsoluteSize.X
local handleWidth = Handle.AbsoluteSize.X
local minScale = 0
local maxScale = 1
local posX = Handle.Position.X.Scale
local minOffset = handleWidth / 2 / trackWidth
local maxOffset = 1 - minOffset
local sliderValue = (posX - minOffset) / (maxOffset - minOffset)
sliderValue = math.clamp(sliderValue, 0, 1)
sliderValue = math.round(sliderValue * num) / num
print(sliderValue)
end)
af_2048 understand this and that is not a workaround. In fact he’s has even accounted for different widths..