Dragger Function Using Scale Not Offset?

I have created a Dragger function but when I move the Frame up and down the mouse moves along the Frame instead of staying in the middle. Here is my code

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")

local RBXScriptConnection = {}

local CurrentCamera = workspace.CurrentCamera
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()

local Draggable = function(Frame)
	table.insert(RBXScriptConnection, Frame.InputBegan:Connect(function(InputBegan)
		if InputBegan.UserInputType == Enum.UserInputType.MouseButton1 then
			local Position = Vector2.new(Frame.Position.X.Scale, Frame.Position.Y.Scale)
			while RunService.RenderStepped:Wait() and UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) do
				Frame.Position = UDim2.new(Mouse.X / CurrentCamera.ViewportSize.X - Frame.Size.X.Scale / 2, 0, Mouse.Y / CurrentCamera.ViewportSize.Y - Frame.Size.Y.Scale / 2, 0)
			end
		end
	end))
end

I know using offset instead of scale can fix this but I want to use scale so how can I stop this happening? Using Scale not offset.

Can you provide a video/gif of what is happening right now? It’s really hard to understand your description of the issue.

robloxapp-20210503-1546290.wmv (560.1 KB)

You can see how it is not in the middle of the GUI and when I move it side to side the mouse moves a bit left/right. I want to fix this using scale I know offset works fine in fixing this problem.

Check if your AnchorPoint for the frame is set to 0,0 and also make sure the frame has 0 offset size.

Yep both those things are 0 but it is still doing that

There is no other way this could possibly be happening from my knowledge. Can’t help you then, sorry.

Well it must have something to do with ViewportSize

You are setting it to scale, write it like

UDim2.new(0,offset,0,offset)

instead of

UDim2.new(scale,0,scale,0

Thread is the first not second

UDim2.new(Scale, Offset, Scale, Offset) Scale is a number between 0 and 1 thus why I am dividing by ViewportSize. You are saying to set the position using Offset the second and fourth argument when I want to set the position using Scale first and third

I see what you are trying to do.

You can convert offset to scale by doing

offset / ViewportSize

Hey, sorry to ask, but I’m on my phone and I can’t look at that file, could you upload it as a GIF (via online file converters) so I can see it? I really think I can help ya here.

Mouse.X is an offset so thats is what I am doing

Okay tell me if I am getting this right what you are trying to do.

You want to drag something with scale so that it will look the same on all screen resolutions?

Kinda I want to drag the frame using scale. SO it looks like when you drag it using Offset. Video:

robloxapp-20210503-1612151.wmv (341.3 KB) Using offset see how the mouse is in the centre and does not move along the frame when going up down left or right

Imgur: The magic of the Internet eew

Oh, I think I know what you mean. You want to make it almost like a volume slider, correct? It so, just remove the X in your udim2, e.g:

 UDim2.new(Frame.Position.X.Scale, 0, Mouse.Y / CurrentCamera.ViewportSize.Y - Frame.Size.Y.Scale / 2, 0)

So you want it to look like what you showed in the video, just using scale?

No I want it to look like this

but using scale instead of offset

Yes that is exactly what I want but my code allows the mouse to move slightly along the frame not keeping it in the centre. Can you help fix this?