Weird movements also letting go without letting go mouse button

Im making a drag system but when I started testing on players, it would just let go and glitching

What It should look normally

The bug

I’ve tried mouse filter but it doesn’t work since it only does for 1 model, tried looking for similar problems in yt/ devfourm, still nope.

Code:

local ContextActionService = game:GetService("ContextActionService")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local GrabObject = nil
local GrabStart = false
local Dragger = nil
local RotatingR = false
local RotatingT= false

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

wait()

function weldBetween(a, b)
	local weld = Instance.new("ManualGlue", a)
	weld.C0 = a.CFrame:inverse() * b.CFrame
	weld.Part0 = a
	weld.Part1 = b
	return weld
end

function AddMover(part)
	local NewMover = Instance.new("BodyPosition")
	NewMover.Parent = part
	NewMover.MaxForce = Vector3.new(40000,40000,40000)
	NewMover.P = 40000
	NewMover.D = 1000
	NewMover.Position = part.Position
	NewMover.Name = "Mover"

	local NewRot = Instance.new("BodyGyro")
	NewRot.Parent = part
	NewRot.MaxTorque = Vector3.new(3000,3000,3000)
	NewRot.P = 3000
	NewRot.D = 500
	NewRot.CFrame = game.Workspace.CurrentCamera.CFrame
	NewRot.Name = "RotMover"

	local RotOffset = Instance.new("CFrameValue")
	RotOffset.Name = "RotOffset"
	RotOffset.Parent = part
end


function CreateDragBall()
	local DragBall = Instance.new("Part")
	DragBall.Size = Vector3.new(0.1, 0.1, 0.1)
	DragBall.Shape = "Ball"
	DragBall.Name = "DragBall"
	DragBall.Parent = Player.Character
	DragBall.Transparency = 1
	return DragBall
end

function Grab(ActionName, UserInputState, InputObject)
	if ActionName == "Grab" then
		if UserInputState == Enum.UserInputState.Begin then
			local Magnitude = (Mouse.Hit.Position - Character.Head.CFrame.Position).magnitude
			if Magnitude < 15 then
				if Mouse.Target then
					GrabObject = Mouse.Target
					if GrabObject.Anchored == false then
						GrabStart = true
						local DragBall = CreateDragBall()
						DragBall.CFrame = Mouse.Hit
						Dragger = DragBall
						Mouse.TargetFilter = GrabObject
						local DragBallWeld = weldBetween(DragBall,GrabObject)
						AddMover(DragBall)
						while Dragger do
							local CF = CFrame.new(Character.Head.Position, Mouse.Hit.Position)
							Dragger.Mover.Position = (CF + (CF.LookVector * 10)).Position
							Dragger.RotMover.CFrame = Camera.CFrame * CFrame.Angles(Dragger.RotOffset.Value.X,Dragger.RotOffset.Value.Y, Dragger.RotOffset.Value.Z)
							wait()
						end
						Mouse.TargetFilter = nil
					end
				end
			end
		elseif UserInputState == Enum.UserInputState.End then
			GrabObject = nil
			GrabStart = false
			if Dragger then
				Dragger:Destroy()
				Dragger = nil
			end
		end
	elseif ActionName == "RotateF" then
		if GrabStart == true then
			if Dragger then
				if UserInputState == Enum.UserInputState.End then
					local Info = TweenInfo.new(0.5, Enum.EasingStyle.Circular, Enum.EasingDirection.In)
					local Goal = {Orientation = Vector3.new(0, 0, 0)}
					TweenService:Create(GrabObject, Info, Goal):Play()
				end
			end
		end
	elseif ActionName == "RotateR" then
		if GrabStart == true then
			if UserInputState == Enum.UserInputState.Begin then
				RotatingR = true
				while RotatingR and Dragger do
					GrabObject.Orientation = GrabObject.Orientation + Vector3.new(0, 1, 0)
					wait()
				end
			elseif UserInputState == Enum.UserInputState.End then
				RotatingR = false
			end
		end
	elseif ActionName == "RotateT" then
		if GrabStart == true then
			if UserInputState == Enum.UserInputState.Begin then
				RotatingT = true
				while RotatingT and Dragger do
					GrabObject.Orientation = GrabObject.Orientation + Vector3.new(0, 0, 1)
					wait()
				end
			elseif UserInputState == Enum.UserInputState.End then
				RotatingT = false
			end
		end
	end
end

ContextActionService:BindAction("Grab", Grab, true, Enum.UserInputType.MouseButton1)

ContextActionService:BindAction("RotateF", Grab, true, Enum.KeyCode.F)

ContextActionService:BindAction("RotateR", Grab, true, Enum.KeyCode.R)

ContextActionService:BindAction("RotateT", Grab, true, Enum.KeyCode.T)

Can you please Preformat your code? It will make it easier for us to understand. How to do it is press this button and then paste your code in the `'s.
image

okay it’s done I just edited it

Alright, thanks for formatting it. Anyways, any errors?

No errors, i also checked the server explorer and properties and nothing changed

So, basically what is happening is that you can take a part from someone else while there grabbing it?

No, just basically when you drag a part near someones character it starts to glitch

Well the first problem is that you are using something deprecated (body movers and your waits should be task.wait). It’s not going to affect how it works but it’s just not recommended. Secondly, you are doing everything on the client, which is risky. Try using remote events and setting the network owner of the parts. (Also do you mind converting wmv’s to mp4’s? I can’t really open them)

there I changed the video files, ill try doing the remote events now

If it still bugs, send your code. I wanna make sure you did it correctly.

Im a bit confused, should i move the instance.new functions to the server script or i just move line where it changes cframe of the part thats dragging in server script

you can do setting network ownership instead of remotes

local ReplicatedStorage = game:GetService("ReplicatedStorage")

GrabEventStart = ReplicatedStorage.RemoteEvents.GrabEventStart

GrabEventEnd = ReplicatedStorage.RemoteEvents.GrabEventEnd

GrabEventStart.OnServerEvent:Connect(function(Player, GrabObject)

GrabObject:SetNetworkOwner(Player.Character)

end)

GrabEventEnd.OnServerEvent:Connect(function(Player, GrabObject)

GrabObject:SetNetworkOwnerAuto()

end)

i just looked at some information about it, i have never used it before but it says index nil in the output

You can only set network owner from the server, so it’s a requirement to use remotes.

Can you show the local code? Also you might need to use :WaitForCHild() on the remote events because they might have loaded after the code started running.

I didn’t say you don’t need remotes for that, i was reffering to another method

? you said “network ownership INSTEAD of remotes”

I’ve just read your post again and i’ve read it wrong, i thought you were talking about setting the position and rotation of part via sending events to server lol, i’m sorry for misunderstanding

1 Like
local ContextActionService = game:GetService("ContextActionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local GrabObject = nil
local GrabStart = false
local Dragger = nil
local RotatingR = false
local RotatingT= false

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

GrabEventStart = ReplicatedStorage.RemoteEvents.GrabEventStart
GrabEventEnd = ReplicatedStorage.RemoteEvents.GrabEventEnd

wait()

function weldBetween(a, b)
	local weld = Instance.new("ManualGlue", a)
	weld.C0 = a.CFrame:inverse() * b.CFrame
	weld.Part0 = a
	weld.Part1 = b
	return weld
end

function AddMover(part)
	local NewMover = Instance.new("BodyPosition")
	NewMover.Parent = part
	NewMover.MaxForce = Vector3.new(40000,40000,40000)
	NewMover.P = 40000
	NewMover.D = 1000
	NewMover.Position = part.Position
	NewMover.Name = "Mover"

	local NewRot = Instance.new("BodyGyro")
	NewRot.Parent = part
	NewRot.MaxTorque = Vector3.new(3000,3000,3000)
	NewRot.P = 3000
	NewRot.D = 500
	NewRot.CFrame = game.Workspace.CurrentCamera.CFrame
	NewRot.Name = "RotMover"

	local RotOffset = Instance.new("CFrameValue")
	RotOffset.Name = "RotOffset"
	RotOffset.Parent = part
end


function CreateDragBall()
	local DragBall = Instance.new("Part")
	DragBall.Size = Vector3.new(0.1, 0.1, 0.1)
	DragBall.Shape = "Ball"
	DragBall.Name = "DragBall"
	DragBall.Parent = workspace
	DragBall.Transparency = 1
	DragBall.CanCollide = false
	return DragBall
end

function Grab(ActionName, UserInputState, InputObject)
	if ActionName == "Grab" then
		if UserInputState == Enum.UserInputState.Begin then
			local Magnitude = (Mouse.Hit.Position - Character.Head.CFrame.Position).magnitude
			if Magnitude < 15 then
				if Mouse.Target then
					GrabObject = Mouse.Target
					if GrabObject.Anchored == false then
						GrabStart = true
						local DragBall = CreateDragBall()
						DragBall.CFrame = Mouse.Hit
						Dragger = DragBall
						Mouse.TargetFilter = GrabObject
						local DragBallWeld = weldBetween(DragBall,GrabObject)
						AddMover(DragBall)
						GrabEventStart:FireServer()
						while Dragger do
							local CF = CFrame.new(Character.Head.Position, Mouse.Hit.Position)
							Dragger.Mover.Position = (CF + (CF.LookVector * 10)).Position
							Dragger.RotMover.CFrame = Camera.CFrame * CFrame.Angles(Dragger.RotOffset.Value.X,Dragger.RotOffset.Value.Y, Dragger.RotOffset.Value.Z)
							wait()
						end
						Mouse.TargetFilter = nil
					end
				end
			end
		elseif UserInputState == Enum.UserInputState.End then
			GrabObject = nil
			GrabStart = false
			if Dragger then
				Dragger:Destroy()
				Dragger = nil
			end
		end
	elseif ActionName == "RotateF" then
		if GrabStart == true then
			if Dragger then
				if UserInputState == Enum.UserInputState.End then
					local Info = TweenInfo.new(0.5, Enum.EasingStyle.Circular, Enum.EasingDirection.In)
					local Goal = {Orientation = Vector3.new(0, 0, 0)}
					TweenService:Create(GrabObject, Info, Goal):Play()
				end
			end
		end
	elseif ActionName == "RotateR" then
		if GrabStart == true then
			if UserInputState == Enum.UserInputState.Begin then
				RotatingR = true
				while RotatingR and Dragger do
					GrabObject.Orientation = GrabObject.Orientation + Vector3.new(0, 1, 0)
					wait()
				end
			elseif UserInputState == Enum.UserInputState.End then
				RotatingR = false
			end
		end
	elseif ActionName == "RotateT" then
		if GrabStart == true then
			if UserInputState == Enum.UserInputState.Begin then
				RotatingT = true
				while RotatingT and Dragger do
					GrabObject.Orientation = GrabObject.Orientation + Vector3.new(0, 0, 1)
					wait()
				end
			elseif UserInputState == Enum.UserInputState.End then
				RotatingT = false
			end
		end
	end
end

ContextActionService:BindAction("Grab", Grab, true, Enum.UserInputType.MouseButton1)

ContextActionService:BindAction("RotateF", Grab, true, Enum.KeyCode.F)

ContextActionService:BindAction("RotateR", Grab, true, Enum.KeyCode.R)

ContextActionService:BindAction("RotateT", Grab, true, Enum.KeyCode.T)