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