Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- make sure this is in local script named "SmoothDrag"
- local Drag = script.Parent.Parent.MainFrame
- gsCoreGui = game:GetService("CoreGui")
- gsTween = game:GetService("TweenService")
- local UserInputService = game:GetService("UserInputService")
- local dragging
- local dragInput
- local dragStart
- local startPos
- local function update(input)
- local delta = input.Position - dragStart
- local dragTime = 0.04
- local SmoothDrag = {}
- SmoothDrag.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
- local dragSmoothFunction = gsTween:Create(Drag, TweenInfo.new(dragTime, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), SmoothDrag)
- dragSmoothFunction:Play()
- end
- Drag.InputBegan:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
- dragging = true
- dragStart = input.Position
- startPos = Drag.Position
- input.Changed:Connect(function()
- if input.UserInputState == Enum.UserInputState.End then
- dragging = false
- end
- end)
- end
- end)
- Drag.InputChanged:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
- dragInput = input
- end
- end)
- UserInputService.InputChanged:Connect(function(input)
- if input == dragInput and dragging and Drag.Size then
- update(input)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement