This clip is self-explanatory, I want to make it so I don’t create the rectangular selection box when dragging my plugin GUI (parented to CoreGui)
Here’s the “Dragger” class I used to Drag my Gui:
local UIS = game:GetService("UserInputService")
local Dragger = {}
Dragger.__index = function(t, k)
if Dragger[k] then return Dragger[k] end
k = string.lower(k)
if k == "isdragging" then
return t._isDragging
elseif k == "object" then
return t._object
end
end
function Dragger.new(guiObject)
local new = setmetatable({
_isDragging = false,
_object = guiObject,
_offset = UDim2.new(),
_con = nil,
}, Dragger)
guiObject.Destroying:Connect(function() new:Destroy() end)
return new
end
function Dragger:DragBegin()
if self._isDragging then return end
self._isDragging = true
self._offset = self._object.AbsolutePosition - UIS:GetMouseLocation()
self._con = UIS.InputChanged:Connect(function(input, event)
if event then return end
if input.UserInputType == Enum.UserInputType.MouseMovement then
local absPos = UIS:GetMouseLocation() + self._offset
self._object.Position = UDim2.fromOffset(absPos.X, absPos.Y)
end
end)
end
function Dragger:DragStop()
if not self._isDragging then return end
self._isDragging = false
self._con:Disconnect() self._con = nil
end
function Dragger:Destroy()
self = nil
end
return Dragger
Here’s the code where I used these dragging functions:
-- MainFrame is the frame I want to Drag
local mainFrameDrag = Dragger.new(MainFrame)
MainFrame.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
mainFrameDrag:DragBegin()
end
end)
UserInputService.InputEnded:Connect(function(input, event)
if event then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
mainFrameDrag:DragStop()
end
end)
I’m unsure what to name this problem because it’s a weird one so I haven’t been able to find any solutions after Google searches, any help would be appreciated!