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