Space between mouse and slider

The gui for my new slider UI is needing more mouse movement than it should, making it out of sync with the slider visuables.

As you can see here, the mouse is dispositioned from the end of the slider, giving an unsatisfying feel to the interface.

I think this has something to do with the size, as the gap increases as the speed increases.

Slider Code

local UserInputService = game:GetService("UserInputService")
local Dragging = false
Domain.Speed.Amount.Action.MouseButton1Down:Connect(function()
	Dragging = true
end)

UserInputService.InputChanged:Connect(function()
	if Dragging then
		local MousePos = UserInputService:GetMouseLocation()+Vector2.new(0,32)
		local RelPos = MousePos-Domain.Speed.Amount.AbsolutePosition
		local Precent =  math.clamp(RelPos.X/Domain.Speed.Amount.AbsolutePosition.X,0.014444,1)
		wait(0.01)
		local transitionInfo = TweenInfo.new(0.4, Enum.EasingStyle.Quint)
		local tween = TweenService:Create(Domain.Speed.Amount, transitionInfo, {Size = UDim2.new(Precent,0,1,0)})
		tween:Play()
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = Precent*100
		Domain.Speed.Title.Text = tostring(math.floor(game.Players.LocalPlayer.Character.Humanoid.WalkSpeed)).." walkspeed"
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		Dragging = false
	end
end)
1 Like

Since I don’t understand what you were doing in your code, I made my own slider system just for you (which works well I guess). I also labelled things in the script so hopefully you can understand what it does.
SliderTest.rbxl (35.0 KB)

1 Like

Appreciate the help, but the problem with this method, is the clipdescendants part. As I’m using UICorner, the edges on the left, will look square as for some reason roblox hasn’t updated clipdescendants with UICorner.

image

This is why I have to use Size to increase and decrease the slider.

1 Like

In that case, not much change needs to be done. The script already generates an alpha value which is from 0 to 1, and you can just plug that directly into a UDim2 value for the size.

1 Like

Could you possibly change this in the LocalScript provided under Frame, I don’t understand what to do here lmao. It seems to change the Y value of size when I change the .Position to .Size for some weird reason.

Because the Y scale value for the UDim2 is 0, it makes it disappear. Change it back to 1.
SliderTest.rbxl (35.0 KB)

1 Like

Totally missed that, thanks, I’ll keep you updated.

1 Like

You will need to multiply or divide the RelPos or the MousePos.

How do I know what to multiply or divide this by? lol

Just test it out I do not know because yours is different then mine but I divided it to slow it down.

1 Like

I fixed a few flaws with my script, and also added the s m o o t h tweening animation for the slider.
SliderTest (2).rbxl (35.1 KB)

1 Like

One thing that I am confused by is why use they Mouse Y position when the slider is horizontal and why you add 32 to the Y Mouse Pos?

Works great, thank you! Intergrated this code into my UI and looks great.