Dragging Gui Help

I want to make a draggable GUI

When I try to drag it, it glitches out look:
Start:
image

What I get:
image

I have tried youtube.com and devforum.roblox.com

My GUI just teleports to the top right instead of following my mouse I really need help with this because I need it to finish my game. My GUI allows me to paint and everything but will not let me drag it whatsoever.

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

local UserInputService = game:GetService('UserInputService')

local hold = false

function drag()
	
	if hold == false then return end
	
	script.Parent.Parent.Position = UDim2.new(0,Mouse.X,0,Mouse.Y)
end

function inputBegan(input)
	local inputType = input.UserInputType
	if inputType == Enum.UserInputType.MouseButton1 then
		hold = true
	end
end

function inputEnded(input)
	local inputType = input.UserInputType
	if inputType == Enum.UserInputType.MouseButton1 then
		hold = false
	end
end

UserInputService.InputBegan:Connect(inputBegan)
UserInputService.InputEnded:Connect(inputEnded)

script.Parent.MouseMoved:Connect(drag)

Mouse.Hit is a CFrame value, you need to pass Mouse.X and Mouse.Y

1 Like

Wrong one hold on lol :grinning_face_with_smiling_eyes:

It sitll wont work :grinning_face_with_smiling_eyes:

I updated the code here:

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

local UserInputService = game:GetService('UserInputService')

local hold = false

function drag()
	
	if hold == false then return end
	
	script.Parent.Parent.Position = UDim2.new(0,Mouse.X,0,Mouse.Y)
end

function inputBegan(input)
	local inputType = input.UserInputType
	if inputType == Enum.UserInputType.MouseButton1 then
		hold = true
	end
end

function inputEnded(input)
	local inputType = input.UserInputType
	if inputType == Enum.UserInputType.MouseButton1 then
		hold = false
	end
end

UserInputService.InputBegan:Connect(inputBegan)
UserInputService.InputEnded:Connect(inputEnded)

script.Parent.MouseMoved:Connect(drag)

So the entire gui just teleports to the corner and nothing happens? Screenshot the explorer where the GUI is please

OK wait a sec :grinning_face_with_smiling_eyes:

You can also see the app on the bottom right it is meant to stay in the screen and not further and here:
image

@faunx :grinning_face_with_smiling_eyes:

Still here, just thinking why it would teleport the the bottom right

1 Like
UDim2.new((game.Players.LocalPlayer:GetMouse().X / game.Players.LocalPlayer:GetMouse().ViewSizeX)-frame.Size.X.Scale/2,0,(game.Players.LocalPlayer:GetMouse().Y / game.Players.LocalPlayer:GetMouse().ViewSizeY)-frame.Size.Y.Scale/1.25,0)

This is code I’ve used in the past to drag, but I’m not sure whether the issue is down to a property of the GUI or the code itself, try this and see if anything changes. Replace frame with the gui that you want by the way

Now it moves up to the right a little bit look:
image

the issue must be something to do with the properties of the gui
make sure everything is default

I will send all props:
image
image

properties for RoPainter gui object

Wrong one oops :grinning_face_with_smiling_eyes:

Sorry just noticed that lol :grinning_face_with_smiling_eyes:

image
image

Alr last resort, can I get a download of the gui and the script you’re using to test myself and try and find the error

1 Like

GuiYes.rbxm (12.1 KB)