Slider doesn't work

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.

Thanks in advance!

2 Likes

That’s because slider position is never reaches expected limits 0 and 1.
And this is tied to its scale.
The value must be mapped.
This works for me:

Handle:GetPropertyChangedSignal("Position"):Connect(function()
	local sliderPosition = Handle.Position.X.Scale
	local slider_inflation = Handle.AnchorPoint.X * Handle.Size.X.Scale
	local slider_len = 1 - 2 * slider_inflation
	sliderPosition = (sliderPosition - slider_inflation) / slider_len 
	sliderPosition = math.round( sliderPosition * num ) / num
	print(sliderPosition)
end)

With this code you can change slider’s width and it still works.

1 Like

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..

Good to know.

Sorry I didn’t specify, but I was more or less looking for a solution without code. If it doesn’t arise, I will mark af_2048’s post as the solution :D

1 Like

No code.. still mark his as the solution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.