Need help converting position offset to scale

I’m making draggable gui which adjust mouse sensitivity and I need to convert offset to scale for
whenever I start dragging a gui the number increase according to slider position on gui.

Here’s how it’s look like: https://gyazo.com/904ae265416d87fda097c7de99b72b15

Here’s how I increase offsets

slider.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		local lastMousePos = get_mouse_location()
		
		while UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) do
			local delta = get_mouse_location() - lastMousePos
			
			slider.Position = UDim2.new(slider.Position.X.Scale, math.clamp(slider.Position.X.Offset, 10, 360), 0.5, 0) + UDim2.new(0, delta.X, 0, 0)
			
			lastMousePos = get_mouse_location()
			wait()
		end
	end
end)

Not currently sure of what your issue is, but if you want it to indicate the level of sensitivity as the player moves the slider, you can just divide the slider position to the X position.

You can convert your slider’s delta to scale via CurrentCamera.ViewportSize.
Since GUI scaling is based off of 0 to 1, you need to multiply your ViewportSize by the mouse’s position.

local viewportSize = currentCamera.ViewportSize
local delta = get_mouse_location() - lastMousePos

local scaled = delta / viewportSize

This is untested, though, and am unsure if this will work.

It doesn’t seem to work.
https://gyazo.com/1e1de93703499c2ad73a00c22eec8722

Make sure you read the updated edit (delta / viewportSize), since I had to check the math.

Yep, that’s the output I got from it.

local delta = get_mouse_location() - lastMousePos
local scaled = delta / viewportSize
print(scaled)

How exactly are you getting the mouse’s location, and what does your delta output?

Just so this might help, I am seeing how much one scale is to offset

I’m using UIS:GetMouseLocation()

As I have explained, the scale-to-offset is entirely based off of CurrentCamera.ViewportSize, as that’s how big the ROBLOX Player’s window is.

Can you output your delta instead of scaled?

This is what I got from currentMouseLocation - lastMouseLocation
https://gyazo.com/507fad476e95031db45fa6b3d7dda30f

yes that is true, It depends on their view, and device.

This output is to be expected. Scale is a really low number due to you subtracting the last mouse position from the current mouse position. It should still work fine, though?

It’s working fine I’m using delta.X as an offset

 slider.Position = UDim2.new(slider.Position.X.Scale, math.clamp(slider.Position.X.Offset, 10, 360), 0.5, 0) + UDim2.new(0, delta.X, 0, 0)

I would suggest just not having the slider add to its scale with the delta. Offset shouldn’t be much of an issue with sliders, since it’s been used that way since the beginning of time.

the slider is working fine I just want to know how do i adjust the number related to slider position

Sorry, I didn’t understand what you were asking due to the explanation given. I’d suggest dividing the delta by the start position of the slider.

Basically I’m making a slider that adjust the mouse sensitivity.
for example:
if slider is positioning on 0.1 scale it will converted by 0.1 x 10 and using for mousedeltasensitivity

but I have no idea how to do that since I’m using an offset

You can divide the offset of the slider by the starting AbsolutePosition of it, and multiply that by 10.