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