Dragging body brings the NPC back to the starting spot

Hello!
Im currently working on the agent game where if you killed someone. You’ll need to hide their body in order to prevent people from calling the police. However when i stop dragging them it will teleport back to the start position for weird reason. Heres a footage of the problem:

. I used the rope constraint with 0.1 Length to drag the body. This is very frustating because some of them seems to work and some dont. Please help!

2 Likes

Could you share your script for this?

2 Likes

A part of the ragdoll script:
(i dont know how to do the ragdoll so i just get it from the toolbox)

function activate()
	print("Ragdolling");
	local Character = getCharacter();
	local Humanoid = getHumanoid();
	local HumanoidRoot = script.Parent:FindFirstChild("HumanoidRootPart");
	if ( HumanoidRoot == nil ) then
		print("Cannot create ragdoll");
		return;
	end
	local Position = script.Parent.HumanoidRootPart.Position;
	Humanoid.PlatformStand = true;
	
	-- Handle death specific ragdoll. Will Clone you, then destroy you.
	local RagDollModel = Character;
	if ( (Humanoid.Health <= 0) and script.ActivateOnDeath.CloneAndDestroy.Value ) then
		Character:FindFirstChild("HumanoidRootPart"):Destroy();
		Character.Archivable = true;
		RagDollModel = Character:Clone();
		RagDollModel.Name = "RagDoll";
			
		local t = RagDollModel:GetChildren();
		for i=1,#t do
			local t2 = t[i];
			if ( t2:IsA("Script") or t2:IsA("LocalScript") ) then
				t2:Destroy();
			end
		end
		
		spawn(function()
			wait();
			RagDollModel.Humanoid.PlatformStand = true;
			game.Debris:AddItem(RagDollModel, script.ActivateOnDeath.CloneAndDestroy.Delay.Value);
		end)
		
		RagDollModel.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None;
		RagDollModel.Humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff;
		RagDollModel.Humanoid.Health = 0;
		RagDollModel.Parent = game.Workspace.Deads;
		RagDollModel.PrimaryPart = RagDollModel:FindFirstChild("UpperTorso")
		local RagDollPointer = Instance.new("ObjectValue");
		RagDollPointer.Value = RagDollModel;
		RagDollPointer.Name = "RagDoll";
		RagDollPointer.Parent = Character;
	end
	
	-- Reglue The Character
	for i=1,#RootLimbData do
		local limbData = RootLimbData[i];
		local partName = limbData["WeldTo"];
		local weldName = limbData["WeldRoot"];
		local PartTo = RagDollModel:FindFirstChild(partName);
		local WeldTo = RagDollModel:FindFirstChild(weldName);
		
		if ( PartTo ~= nil and WeldTo ~= nil ) then
			if ( RagDollModel ~= nil ) then
				if ( script.ApplyRandomVelocity.Value ) then
					local scale = script.ApplyRandomVelocity.Force.Value;
					local vecX = (math.random()-math.random())*scale;
					local vecY = (math.random()-math.random())*scale;
					local vecZ = (math.random()-math.random())*scale;
					PartTo.Velocity = PartTo.Velocity + Vector3.new(vecX, vecY, vecZ);
				end
				PartTo.Parent = RagDollModel;
			end
			-- Create New Constraint
			local UpperAngle = limbData["UpperAngle"];
			local Joint = Instance.new("BallSocketConstraint");
			if ( (UpperAngle ~= nil and UpperAngle == 0) or (script.WeldHead.Value and partName == "Head") ) then
				Joint = Instance.new("HingeConstraint");
				Joint.UpperAngle = 0;
				Joint.LowerAngle = 0;
			end
			Joint.Name = limbData["AttachmentName"];
			Joint.LimitsEnabled = true;
			Joint.Attachment0 = PartTo:FindFirstChild(Joint.Name .. "RigAttachment");
			Joint.Attachment1 = WeldTo:FindFirstChild(Joint.Name .. "RigAttachment");
			Joint.Parent = PartTo;
			GlueList[#GlueList+1] = Joint;
			if ( UpperAngle ~= nil ) then
				Joint.UpperAngle = UpperAngle;
			end
			
			-- Destroy the motor attaching it
			local Motor = PartTo:FindFirstChildOfClass("Motor6D");
			if ( Motor ~= nil ) then
				if ( Humanoid.Health <= 0 ) then
					Motor:Destroy();
				else
					MotorList[#MotorList+1] = { PartTo, Motor };
					Motor.Parent = nil;
				end
			end
			
			-- Create Collider
			local needsCollider = limbData["NeedsCollider"];
			if ( needsCollider == nil ) then
				needsCollider = true;
			end
			if ( needsCollider ) then
				local B = Instance.new("Part");
				B.CanCollide = true;
				B.TopSurface = 0;
				B.BottomSurface = 0;
				B.formFactor = "Symmetric";
				B.Size = Vector3.new(0.7, 0.7, 0.7);
				B.Transparency = 1;
				B.BrickColor = BrickColor.Red();
				B.Parent = RagDollModel;
				local W = Instance.new("Weld");
				W.Part0 = PartTo;
				W.Part1 = B;
				W.C0 = limbData["ColliderOffset"];
				W.Parent = PartTo;
				ColliderList[#ColliderList+1] = B;
			end
		end
	end

	-- Destroy Root Part
	local root = Character:FindFirstChild("HumanoidRootPart");
	if ( root ~= nil ) then
		RootPart = root;
		if ( Humanoid.Health <= 0 ) then
			RootPart:Destroy();
		else
			RootPart.Parent = nil;
		end
	end	
	
	-- Delete all my parts if we made a new ragdoll
	if ( RagDollModel ~= Character ) then
		print("Deleting character");
		local children = Character:GetChildren();
		for i=1,#children do
			local child = children[i];
			if ( child:IsA("BasePart") or child:IsA("Accessory") ) then
				child:Destroy();
			end
		end
	end
	
	-- Give player physics
	if ( script.GivePlayerPhysics.Value ) then
		local PlayerPhysics = getPlayer();
		if ( script.GivePlayerPhysics.ForceNearestPlayer.Value ) then
			PlayerPhysics = getNearestPlayer( Position );
		end
		
		local Children = RagDollModel:GetChildren();
		for i=1,#Children do
			local Child = Children[i];
			if ( Child:IsA("BasePart") ) then
				Child:SetNetworkOwner(PlayerPhysics);
			end
		end
	end
	
	-- Copy plugins into ragdoll
	local Plugins = script.Plugins:GetChildren();
	for i=1,#Plugins do
		local Plugin = Plugins[i];
		local Copy = Plugin:Clone();
		if ( Copy:IsA("Script") ) then
			Copy.Disabled = false;
		end
		Copy.Parent = RagDollModel;
	end
end
1 Like

From what I can see, that function does not handle your rope, it only ragdolls the player.

2 Likes

Can you give me more explanation please

2 Likes

How are you creating the rope? How are you releasing the rope? Where is the code for that?

1 Like
script.Parent.DragEvent.OnServerEvent:Connect(function(player,mousetarget,dragging)
	if dragging == true then
		if mousetarget then
			local humanoid =humanoid
			if humanoid then
				humanoid.Parent:WaitForChild("UpperTorso").CFrame += Vector3.new(0,3,0)
				draganim:Play()
				root.C0 = lastrootc0 * CFrame.Angles(0,179,0)
				rope.Attachment1 = footattachment
			end
		end
	elseif dragging == false then
		root.C0 = lastrootc0
		rope.Attachment1 = nil
		draganim:Stop()
	end
end)

A code from the mouse!

1 Like

What is root? What is lastrootc0? I think this has something to do with the unexpected behavior.

1 Like

The Players body rotation. Players will be behind and when its finished. The player will go to the front (which is default). Pretty sure it has nothing to do with it

1 Like

Try removing the line, see if it changes anything.

2 Likes


It doesnt work :frowning:

1 Like

This might be because you’re dragging the torso and not the HumanoidRootPart. Whenever the player lets go you should update the HumanoidRootPart to the position of the torso. Or alternatively, you could connect the torso to the root and make the player drag it. Unless you’ve figured out another way of course.

1 Like

very late to this but take inspiration on this code. hope this helps many new devs experiencing the same

local rope
local at1
local ishold = false
local oldpos

script.Parent:WaitForChild(“Torso”):WaitForChild(“drag”).Triggered:Connect(function(plr)
if ishold == false then
rope = Instance.new(“RopeConstraint”)
rope.Parent = workspace
at1 = Instance.new(“Attachment”)
at1.Parent = plr.Character:WaitForChild(“Left Arm”)
rope.Attachment0 = at1
rope.Attachment1 = script.Parent:WaitForChild(“Left Arm”).Attachment
rope.Length = 0.5
ishold = true
else

	script.Parent:WaitForChild("Torso").Anchored = true
	script.Parent:WaitForChild("Left Arm").Anchored = true
	script.Parent:WaitForChild("Left Leg").Anchored = true
	script.Parent:WaitForChild("Right Arm").Anchored = true
	script.Parent:WaitForChild("Right Leg").Anchored = true
	script.Parent:WaitForChild("Head").Anchored = true
	
	
	script.Parent:WaitForChild("Torso").Position = script.Parent:WaitForChild("Torso").Position
	script.Parent:WaitForChild("Head").Position = script.Parent:WaitForChild("Head").Position
	script.Parent:WaitForChild("Left Arm").Position = script.Parent:WaitForChild("Left Arm").Position
	script.Parent:WaitForChild("Left Leg").Position = script.Parent:WaitForChild("Left Leg").Position
	script.Parent:WaitForChild("Right Arm").Position = script.Parent:WaitForChild("Right Arm").Position
	script.Parent:WaitForChild("Right Leg").Position = script.Parent:WaitForChild("Right Leg").Position
	
	
	rope.Attachment0 = script.Parent:WaitForChild("Left Arm").Attachment
	rope:Destroy()
	

	script.Parent:WaitForChild("Torso").Anchored = false
	script.Parent:WaitForChild("Left Arm").Anchored = false
	script.Parent:WaitForChild("Left Leg").Anchored = false
	script.Parent:WaitForChild("Right Arm").Anchored = false
	script.Parent:WaitForChild("Right Leg").Anchored = false
	script.Parent:WaitForChild("Head").Anchored = false
	

	
	rope = nil
	at1 = nil
	ishold = false
	

end

end)