How do i make a drag system thats not terrible?

idk what to say, but i want a dragging system for my game. how would i do that?
Im not asking for someone to make a script im seeing if anyone knows about a script that does this or can help me learn to make one, thanks!

1 Like

Without creating a completely custom system from the ground up, you could experiment with Drag Detectors, (which is somewhat new, as it was introduced just last year), to see if that works for what you’re trying to create

1 Like

i had said Not Terrible in my post.

1 Like

A way I created my drag system was using alignorientation and alignposition. I had parented both those instances inside the unanchored part and inserted them into a table and whenever the user unclick the mouse, it destroys all objects in that table to make destroying easier. Than in renderstepped, I made an offset from the mouse and the players head with the same distance they grabbed the object at. I can give you the code snippets for it if you need.

can i use your drag system? or do i not have permission

yea ill just give u one script cuz that’s all u need 4 t to work sorry for late reply tho

maxdistance is self explain but magnitude idk I forgot what it is

local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local Mouse = Player:GetMouse()

local CanClick = true

local MaxDistance = 15
local Magnitude = 10
local Offset = Vector3.new(0,1.5,0)

local PartsToDestroy = {}

local SelectionBox = script.SelectionBox
local DefaultLineThickness = SelectionBox.LineThickness
local DefaultColor3 = SelectionBox.Color3

local CurrentMover = nil
local CurrentOrien = nil
local CurrentSelected = nil

local HoldingLShift = false
local HoldingW = false
local HoldingA = false
local HoldingS = false
local HoldingD = false

local savedRotation
local savedRotationCF
local RotOffset = CFrame.Angles(0,0,0)

local Align = Instance.new("AlignPosition")
local Orien = Instance.new("AlignOrientation")

local RunService = game:GetService("RunService")

local function UnGrab()
	RotOffset = CFrame.Angles(0,0,0)
	for _,v in PartsToDestroy do
		v:Destroy()
	end
end

Mouse.Button1Down:Connect(function()
	local Target = Mouse.Target
	if Target then
		local MeasureDistance = (Target.Position-Player.Character.HumanoidRootPart.Position+Offset).Magnitude

		if not Target:FindFirstChildWhichIsA("ClickDetector") and CanClick == true and  MeasureDistance <= MaxDistance then
			local Owner = Target:FindFirstChild("Owner")
			if Owner then
				if Owner.Value~=Player.UserId then
					return
				end
			end

			game.ReplicatedStorage.SetOwnership:FireServer(Target)

			CurrentSelected = Target

			local spher = script.Sphere:Clone()
			spher.Position = Mouse.Hit.Position
			spher.CFrame = CFrame.lookAt(spher.Position,Player.Character.Head.Position)
			spher.Anchored = false
			spher.Weld.Part1 = Target
			spher.Weld.C1 = Target.CFrame:Inverse()
			spher.Weld.C0 = spher.CFrame:Inverse()
			spher.Parent = Target
			table.insert(PartsToDestroy,spher)

			local a = Instance.new("Attachment")
			a.Parent = spher
			a.CFrame = Target.CFrame.Rotation
			Magnitude = (a.WorldPosition-Player.Character.HumanoidRootPart.Position+Offset).Magnitude
			table.insert(PartsToDestroy,a)

			local a0 = Instance.new("Attachment")
			a0.Parent = spher
			a0.Position = Vector3.new(1,0,0)
			table.insert(PartsToDestroy,a)

			local c = Align:Clone()
			c.Parent = spher
			c.Attachment0 = a
			CurrentMover = c
			table.insert(PartsToDestroy,c)

			local c = Orien:Clone()
			c.CFrame = Target.CFrame
			--HeadPart.Attachment.CFrame = CFrame.new(0,0,0)*Target.CFrame.Rotation
			c.Parent = spher
			c.Attachment0 = a
			CurrentOrien = c
			savedRotation = CurrentSelected.CFrame.Rotation
			savedRotationCF = CurrentSelected.CFrame.Rotation
			table.insert(PartsToDestroy,c)

			--[[local c = SelectionBox:Clone()
			c.Color3 = DefaultColor3
			c.LineThickness = DefaultLineThickness*2
			c.Parent = Camera
			c.Adornee = Target
			table.insert(PartsToDestroy,c)]]

		end

	end
end)

Mouse.Button1Up:Connect(function()
	UnGrab()
end)

game:GetService("UserInputService").InputBegan:Connect(function(i,g)
	if g == false and CurrentSelected then
		if i.KeyCode == Enum.KeyCode.LeftShift then
			HoldingLShift = true
			local Humanoid = Player.Character:FindFirstChildWhichIsA("Humanoid")
			if Humanoid then
				Humanoid.WalkSpeed = 0
			end
		end
		if i.KeyCode == Enum.KeyCode.W then
			HoldingW = true
		end
		if i.KeyCode == Enum.KeyCode.A then
			HoldingA = true
		end
		if i.KeyCode == Enum.KeyCode.S then
			HoldingS = true
		end
		if i.KeyCode == Enum.KeyCode.D then
			HoldingD = true
		end
	end
end)

game:GetService("UserInputService").InputEnded:Connect(function(i,g)
	if g == false and CurrentSelected then
		if i.KeyCode == Enum.KeyCode.LeftShift then
			HoldingLShift = false
			local Humanoid = Player.Character:FindFirstChildWhichIsA("Humanoid")
			if Humanoid then
				Humanoid.WalkSpeed = game.StarterPlayer.CharacterWalkSpeed
			end
		end
		if i.KeyCode == Enum.KeyCode.W then
			HoldingW = false
		end
		if i.KeyCode == Enum.KeyCode.A then
			HoldingA = false
		end
		if i.KeyCode == Enum.KeyCode.S then
			HoldingS = false
		end
		if i.KeyCode == Enum.KeyCode.D then
			HoldingD = false
		end
	end
end)

Align.Enabled = true
Align.Mode = Enum.PositionAlignmentMode.OneAttachment
Align.Responsiveness = 40
Align.MaxForce = 30000

Orien.Responsiveness = 120
Orien.MaxTorque = 12000
Orien.Enabled = Align.Enabled
Orien.Mode = Enum.OrientationAlignmentMode.OneAttachment
--Orien.AlignType = Enum.AlignType.PrimaryAxisLookAt

SelectionBox.Parent = Camera


RunService.RenderStepped:Connect(function()
	if not Player.Character then
		return
	end
	local Target = Mouse.Target
	local HPGoal = Player.Character.Head.Position
	local Adornee = nil
	local Origin = Player.Character.HumanoidRootPart.Position+Offset
	local Pos = Origin+Mouse.Hit.LookVector*Magnitude

	if Target then
		Adornee = Target
	else
		Adornee = nil
	end

	if CurrentSelected then
		if CurrentMover then
			CurrentMover.Position = Pos
		end
		if CurrentOrien then
			CurrentOrien.CFrame = (CFrame.lookAt(CurrentSelected.Position, Origin) * savedRotation * RotOffset).Rotation
		end
		--[[if CurrentOrien then
			CurrentOrien.CFrame=
		end]]
		if (CurrentSelected.Position-Player.Character.HumanoidRootPart.Position+Offset).Magnitude > MaxDistance then
			UnGrab()
		end
	end

	if Player.Character:FindFirstChildWhichIsA("Tool") or Player.Character:FindFirstChildWhichIsA("Humanoid"):GetState() == Enum.HumanoidStateType.Seated then
		CanClick = false
		if CurrentSelected then
			UnGrab()
		end
	else
		CanClick = true
	end

	--SelectionBox.Adornee = Adornee
end)

local RotateAmount = math.rad(10)

while wait(.1) do
	if HoldingLShift then
		if CurrentOrien then
			
			if HoldingW then
				RotOffset*=CFrame.Angles(0,0,RotateAmount)
			end
			if HoldingA then
				RotOffset*=CFrame.Angles(0,RotateAmount,0)
			end
			if HoldingS then
				RotOffset*=CFrame.Angles(0,0,-RotateAmount)
			end
			if HoldingD then
				RotOffset*=CFrame.Angles(0,-RotateAmount,0)
			end
			
		end
	end
end

oh put in starterplayerscripts

oh wait no I forgot u need replicatedstorage remoteevet to set ownership then make a script on call:

--server script
game.ReplicatedStorage.SetOwnership.OnServerEvent:Connect(function(Player,Part)
	local Owner = Part:FindFirstChild("Owner")

	if Owner then
		if Owner.Value ~= Player.UserId then
			warn("nah, "..Player.UserId.." you arent "..Owner.Value)
			return 
		end
	end

	print("Fired")
	workspace:FindFirstChildWhichIsA("Part")
		repeat
			Part:SetNetworkOwner(Player)
			task.wait()
		until Part:GetNetworkOwner() == Player

		for _,v in Part:GetConnectedParts() do
			Part:SetNetworkOwner(Player)
		end

end)

only add SetOwnership the other stuff is for the game
image

im sorry im just curious, what the hell is “check HMMMMMMMMMMMMMMMMM”

uhhhhhhh I forgot also I jsst realized im missing a lot of stuff so I just made it a public small kit for everybody to use

the kit says stuff where to put

edit: it was private I made it public tho

I checked my scripts and its not even used anywhere I have no idea why its there