I’d like to make it so that an entire frame is dragged using UIDragDetector but only when the mouse is in a certain part of that frame. For example, on a PC, you can only drag around a window using the top part of the window. See the diagram below for clarification. In essence, I want the white frame and black frame (which is inside the white frame) to be dragged along only when the black frame is dragged.
Also, for clarification, I don’t want to use MouseEnter and MouseLeave since they are notoriously unreliable, especially with UIDragDetectors.
Make the Drag Part a separate UI object and select it in the BoundingUI property of the UIDragDetector. Parent the UIDragDetector to object that needs to be moved. Worked for me.
There are a couple of problems with this. Firstly, if you drag the UI at any speed above snail’s pace, the drag lags significantly. It also means that you can now drag the UI off the screen, and thus the method can’t be used unfortunately.
Okay I’ve tested this in studio and live game, worked pretty smoothly for me.
local UserInputService = game:GetService("UserInputService")
local mainFrame = script.Parent -- The entire frame to be moved --
local draggableArea = mainFrame:WaitForChild("TextLabel") -- Draggable area --
local isDragging = false
local dragStart
local startPos
local function updateFramePosition(input)
local delta = input.Position - dragStart
mainFrame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
end
draggableArea.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
isDragging = true
dragStart = input.Position
startPos = mainFrame.Position
input.Changed:Once(function()
if input.UserInputState == Enum.UserInputState.End then
isDragging = false
end
end)
end
end)
UserInputService.InputChanged:Connect(function(input)
if isDragging and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then
updateFramePosition(input)
end
end)
I ended up finding a makeshift solution whereby the UIDragDetector will be disabled if the mouse enters the MainFrame, thus leaving the drag frame. I tried doing it whereby it would enable when it entered the drag frane, but the frame was too thin with respect to its height for it to work properly. The MainFrame is quite large, and thus it was able to work better and work with Roblox’s built-in UIDragDetector, although I will say that they should add better features to such a crucial issue and fix its bugs..!
Have you tried the code I provided? It doesn’t rely on UIDragDetector at all.
I wanted to use a UIDragDetector for my code, so therefore I wasn’t able to use yours. I already have code for a custom drag system, but I wanted to try it with Roblox’s built-in one. Thank you for all of your help though! ![]()
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
