Handcuffs not really working anymore

I try to explain the problem as short as possible.
So I have been trying to make a handcuffing/ arrest system like I did a long time ago using welds.
But it’s now that I encountered a problem. Whenever I click on a player (currently a Dummy for quick testing) it puts them infront of me like normal but I am unable to walk forwards and backwards. I can still turn my character and the target turns along with it. However, when I jump and walk forwards/ backwards I move very very slowly in the facing direction.

I’ve tried using a different method with the RunService, however, when I am using .Hearbeat the target lags behind so it’s not really an option. Using .RenderStepped does not work on the server!

(Note that I have the code below only handles the “cuffing” case as of now and not the “realeasing” case)

Here is the Code for the client:

local Player = game.Players.LocalPlayer
local Cuff_Highlight = script:WaitForChild("Cuff_Selection")
local Mouse = Player:GetMouse()

local rfunc_Cuff = game.ReplicatedStorage:WaitForChild("rfunc_Cuff")

local CUFFING_DISTANCE = 8

local PreHighlight = nil

local function RemoveHighlight() 
     if (PreHighlight) then 
		PreHighlight:Remove() 
		PreHighlight = nil
	end
end

Mouse.Move:Connect(function()
	local Target = Mouse.Target

	if (Target == nil) then 
		RemoveHighlight()
		return 
	end
	
    -- if the mouse houvers over a player within reach, the player's character gets highlighted
	if (Target.Parent:FindFirstChild("HumanoidRootPart") --[[and game.Players:FindFirstChild(Target.Parent.Name)]]) then
		local Distance:number = (Player.Character:FindFirstChild("HumanoidRootPart").Position - Target.Parent.HumanoidRootPart.Position).magnitude
		print(Distance.." studs away from target")

		if (Distance < CUFFING_DISTANCE) then 
			if (PreHighlight == nil) then 
				PreHighlight = Cuff_Highlight:Clone()
				PreHighlight.Parent = Target.Parent
			end
		else 
			RemoveHighlight()
		end
	else 
		RemoveHighlight()
	end
end)

Mouse.Button1Down:Connect(function()
	local Target = Mouse.Target
	
	if (Target == nil) then return end
	if (Target.Parent:FindFirstChild("HumanoidRootPart") --[[and game.Players:FindFirstChild(Target.Parent.Name)]]) then 
		local Cuffed = rfunc_Cuff:InvokeServer(Player, Target.Parent.HumanoidRootPart)
		
		if (Cuffed) then
		   -- Target has been cuffed
		end		
	end
end)

Here is the Code that runs on the Server:

local rfunc_Cuff = game.ReplicatedStorage:WaitForChild("rfunc_Cuff")

local HasCuffed = {}


rfunc_Cuff.OnServerInvoke = function(Player, VerifyPlayer, Target)
    -- sanity checks
	if (Target == nil) then return false end 
	if (Player ~= VerifyPlayer) then Player:Kick("Uncaught Exception") end 
	
	if (table.find(HasCuffed, Player.Name)) then 
		return false
	end
	
    -- verifying distance
    local Distance = (Player.Character:FindFirstChild("HumanoidRootPart").Position-Target.Position).magnitude
	if ( Distance < 8) then
        -- Handling the cuffing
		table.insert(HasCuffed, Player.Name)
		local TargetHumanoid = Target.Parent.Humanoid
		
		TargetHumanoid.WalkSpeed = 0
		TargetHumanoid.JumpPower = 0
		
        -- editing the Target
		for i, part in pairs(Target.Parent:GetChildren()) do
			if (part:IsA("BasePart")) then 
				part.Massless = true
				part.CanCollide = false
			end
		end
		
        -- moving the target 1.75 studs infront of the player
		local CFrame = Player.Character.HumanoidRootPart.CFrame
		Target.Parent.HumanoidRootPart.CFrame = CFrame + CFrame.LookVector * 1.75
		
        -- weld constraint
		local CuffWeld = Instance.new("WeldConstraint")
		CuffWeld.Parent = Player.Character.HumanoidRootPart
		CuffWeld.Part1 = Target.Parent.HumanoidRootPart
		CuffWeld.Part0 = Player.Character.HumanoidRootPart
		
		return true
	end
end

Here is a video:

My assumption is that the weight of the other player is forcing you to slow down. I’ve made a handcuff system myself in the past, and I found that making the character massless gets you the best results. For my system, although abusable, I also turned off collisions to avoid any extra force that might be applied.

1 Like

As you can see by the code, I am already making the target’s character massless and uncollidable.

Didn’t read that part. My bad. The only thing I can recommend at this point is setting the NetworkOwnership of the cuffed player to the player cuffing (make sure you set it back when the player is no longer grabbed by another player). I kind of skipped most of these issues since I used a CFrame system because of the many troubles I had with welds (most notably, the lagging like yours and the kill chain effect). If NetworkOwnership doesn’t work, then maybe try using something like AlignPosition and AlignOrientation instead of a weld. As far as I know, this is a common issue for weld cuffs. You could also try lifting the cuffed player a small amount off of the ground and putting them into PlatformStand.

So it seems that the script works fine although the player who is being arrested is too heavy to be moved easily. Try a few things to make the player easier to move:

  • Using strong AlignPosition and Attachments instead of welds
  • Setting the detained player network ownership to the detainer (might not be possible)
  • Using CustomPhysicalProperties
  • PlatformStand
  • Using a fake character mimicing the detained player, which will ideally be lighter

I am now using the AlignPosition/ AlignOrientation just as you two suggested me to use.
I got it to work, however, there was a small problem with position the Attachement of the Player (Police Officer). The Officer’s attachement should be around 2 studs away from the officer’s body but it ended up being hundreds of studs off. When I use the same Code on a newly created part then it works fine.

Here is what I used for the part: PartCop.CFrame = Cop.CFrame + Cop.CFrame.LookVector * 2
When I use the same code on the Attachment then its about 100 studs off.
When removing the Cop.CFrame + it’s now 2 studs away from the cop but it’s not 2 studs away by the LookVector of the Cop.

I hope my explaination of the problems makes sense.

I also noticed that although the Character of the Target is completely uncollidable, it somehow collides with other objects still.

I am not quite sure how CFrame works, so I can’t completely tell what is wrong (I will assume it is the fact that you are adding Cop.CFrame). What I did for my cuff script is the following:

GrabbingHumanoidRootPart.CFrame = HumanoidRootPart.CFrame * CFrame.new(0, 0, -2.5)
GrabbingHumanoidRootPart.Velocity = Vector3.new(0, 0, 0)

And the reason for the velocity was because the character kept “falling”. Try it and tell me how it works out.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.