Trouble with Dragging System (starmaq's Dragging system)

I’m using this system here https://devforum.roblox.com/t/dragging-objects-with-the-mouse/403766 for a game I’m making! Every little bit or so, my “draggable” blocks will return to their original positions so they don’t get lost, make a mess, etc. This part is the issue…

It sends me about 1 bajillion errors in the console. specifically over line 109 in the DraggableModule. I think I understand why, it’s because it moves out of the distance it was before when it’s being dragged around by a player, so the system struggles to calculate where the part should be or something and goes koo koo.

I don’t really know how to make this issue stop, I’m pretty newb to scripting and this is kind of advanced for me ahah. If there’s any way to make the script recognize when a part leaves a certain distance and just force the player to drop it, or something like that it might help, but I really don’t in-depth understand what it wants from me. :smiling_face_with_tear: I’ve had no other problems with this system really, it does exactly what I want but this monstrous mountain of errors is a pain in the neck.

Here’s line 109 and the few strings beneath it

local result = RayCast(distance, {target.Parent or target, holdGrip})
					local cframe = CFrame.new(result and result.Position or character.Head.Position + ((mouse.Hit.Position - character.Head.Position).Unit * distance))
					attachment1.WorldCFrame =  (cframe * CFrame.Angles(cframe:ToEulerAnglesXYZ()):Inverse()) * (attachment1.WorldCFrame - attachment1.WorldCFrame.Position) * newOrientation 
				end)

1 Like

target must be nil, so what is target set to?

I believe the target in question is the part selected in this case, since from what IO can tell the “Parent” is the player’s grip thingamabobber generated from dragging the item around?

local oldOrientation, newOrientation = nil, CFrame.new()
local beganConnection, endConnection, draggingConnection


local function RayCast(distance, ignore)
	local PARAMS = RaycastParams.new()
	PARAMS.FilterType = Enum.RaycastFilterType.Blacklist
	PARAMS.FilterDescendantsInstances = {character, unpack(ignore or {})}
	PARAMS.IgnoreWater = false

	return workspace:Raycast(character.Head.Position, ((mouse.Hit.Position - character.Head.Position).Unit * distance), PARAMS)
end

local function cleanup(distance)
	if target and not target.Anchored then
		local target_ = target
		target = nil
		hit = nil
		newOrientation = CFrame.new()
		if draggingConnection then
			draggingConnection:Disconnect()
		end
		CAS:UnbindAction("rotateDragged")
		oldOrientation = nil
		if holdGrip then
			holdGrip:Destroy()
		end
		holdGrip = nil
		if workspace.Terrain:FindFirstChild("DragAttachment") then
			workspace.Terrain.DragAttachment:Destroy()
		end

From taking a look at what’s referenced in the script as “nil”, I think that may indeed be the case. And the system is bugging when the object moves orientation/position to reset, so it can’t index it as it does in the script (thus giving errors)