Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UserInputService = game:GetService("UserInputService")
- function AddDrag(frame)
- local dragging
- local dragInput
- local dragStart
- local startPos
- local MB1,END,Movement=Enum.UserInputType.MouseButton1,Enum.UserInputState.End,Enum.UserInputType.MouseMovement
- frame.InputBegan:Connect(function(input)
- if input.UserInputType == MB1 then
- dragging = true
- dragStart = input.Position
- startPos = frame.Position
- input.Changed:Connect(function()
- if input.UserInputState == END then
- dragging = false
- end
- end)
- end
- end)
- frame.InputChanged:Connect(function(input)
- if input.UserInputType == Movement then
- dragInput = input
- end
- end)
- UserInputService.InputChanged:Connect(function(input)
- if input == dragInput and dragging then
- local delta = input.Position - dragStart
- frame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
- end
- end)
- end
- return AddDrag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement