How to make a draggable ui? without depracated methods

Hey. I’m trying to make a draggable frame but frame.Draggable is depracated now… so what do I do?

1 Like

Isn’t there a checkbox in the properties menu.

Or is that what is deprecated?

which property would it be

asdfasdfasdfa

I believe this piece of code should allow you to “drag” gui elements. There are a few bits of information you should be wary of being using it though.

Remember to create a TextButton within the Frame which you want to “drag”. Make this button completely invisible by setting the BackgroundTransparency property to 1, in addition, the TextTransparency property likewise. And lastly, set the size of the button to cover the entire Frame via setting the Size property to {1, 0, 1, 0} respectively.

After you’ve done that, name the newly created button Activate and create a LocalScript within the Frame with this code as the source:

-- services
local userInputService = game:GetService("UserInputService")
local players = game:GetService("Players")

-- variables
local player = players.LocalPlayer
local mouse = player:GetMouse()

local frame = script.Parent
local activateButton = frame:WaitForChild("Activate")

local bindedUpdateSignal

-- functions
local function updateFramePosition()
	frame.Position = UDim2.fromOffset(mouse.X, mouse.Y)
end

local function loseFocus()
	if (bindedUpdateSignal) then
		bindedUpdateSignal:Disconnect()
		bindedUpdateSignal = nil
	end
end

activateButton.MouseButton1Down:Connect(function()
	bindedUpdateSignal = mouse.Move:Connect(updateFramePosition)
end)

userInputService.InputEnded:Connect(function(inputObject: InputObject)
	if (inputObject.UserInputType == Enum.UserInputType.MouseButton1 or inputObject.UserInputType == Enum.UserInputType.Touch) then
		loseFocus()
	end
end)

I hope this helps :slight_smile:

p.s. If you run into any problems just let me know.

Edit: Here’s how the hierarchy should be structured:
image

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.