Handcuff System Bugs

Hi all, hope you’re well. I’ve been working on a handcuff system that has a grab & pin feature. Everything works great! A part from the “Pin” feature, for some bizarre reason that I can’t seem to wrap my head around, you need to double tap H to unpin someone?

When someone is cuffed, all of their tools are put into a folder in ReplicatedStorage, when they are uncuffed, their tools get placed back in their Backpack and the folder is deleted. This works perfectly, again, until you pin someone, I’ve tried re-writing this part of the code a few times with different methods, to no avail. Any help is greatly appreciated, I’ve attached some of the code below!

Local Script (Inside the tool)

UserInputService.InputBegan:Connect(function(Key)
	if Key.KeyCode == Enum.KeyCode.G then
		if Equipped == true then
			if Mouse.Target then
				local targetPlayer = game.Players:GetPlayerFromCharacter(Mouse.Target.Parent)
				Events.Grab:FireServer(targetPlayer)
			end
		else
			return
		end
	elseif Key.KeyCode == Enum.KeyCode.H then
		if Equipped == true then
			if Mouse.Target then
				local targetPlayer = game.Players:GetPlayerFromCharacter(Mouse.Target.Parent)
				Events.Pin:FireServer(targetPlayer)
			end
		else
			return
		end
	end 
end)

Script (Inside the tool)

function Pin(Player, TargetPlayer)
	if Cuffed[TargetPlayer] == true then
		Anim = TargetPlayer.Character.Humanoid:LoadAnimation(PinnedAnimation)
		task.wait(0.2)
		if Anim.IsPlaying == true then
			Anim:Stop()
			TargetPlayer.Character.Humanoid.WalkSpeed = 16
		elseif Anim.IsPlaying == false then
			Anim:Play()
			TargetPlayer.Character.Humanoid.WalkSpeed = 0
		end
	else
		return
	end
end

Events.Pin.OnServerEvent:Connect(Pin)

Thanks in advance!

2 Likes

Why can’t you just hide the cuffed player backpack gui?

I did think about that, but it was ultimately easier to do it this way!

function Cuff(Cuffed:boolean?, CuffedPlayer:Player?)
	if Cuffed then -- Cuffed
		local Folder = Instance.new("Folder")
		Folder.Name = CuffedPlayer.Name
		Folder.Parent = game:GetService("ReplicatedStorage")
		CuffedPlayer.Character:FindFirstChildOfClass("Humanoid"):UnequipTools()
		for _,v in CuffedPlayer.Backpack:GetChildren() do
			if v:IsA("Tool") then
				v.Parent = Folder
			end
		end
	else
		for _,v in game:GetService("ReplicatedStorage"):FindFirstChild(CuffedPlayer.Name) do
			if v:IsA("Tool") then
				v.Parent = CuffedPlayer.Background
			end
		end
		game:GetService("ReplicatedStorage"):FindFirstChild(CuffedPlayer.Name):Destroy()
	end
end

function Pin(Player, TargetPlayer)
	if Cuffed[TargetPlayer] == true then
		Anim = TargetPlayer.Character.Humanoid:LoadAnimation(PinnedAnimation)
		task.wait(0.2)
		if Anim.IsPlaying == true then
			Cuff(false, TargetPlayer) -- Player is no longer pinned?
			Anim:Stop()
			TargetPlayer.Character.Humanoid.WalkSpeed = 16
		elseif Anim.IsPlaying == false then
			Cuff(true, TargetPlayer) -- Player is pinned here? 
			Anim:Play()
			TargetPlayer.Character.Humanoid.WalkSpeed = 0
		end
	else
		return
	end
end

I have all of the cuffing part working, it’s just the pinning part I’m having problems with. When I pin someone, I need to press H twice to unpin them (it should just be pressed once).

Fixed this by making changes to the code. Attached below is the fix.

function Pin(Player, TargetPlayer, Pinned)
	task.wait(0.1)
	if Pinned == false then
		local Anim = TargetPlayer.Character.Humanoid:LoadAnimation(PinnedAnimation)
		Anim.Name = "Pinned"
		Anim:Play()
		TargetPlayer.Character.Humanoid.WalkSpeed = 0
	elseif Pinned == true then
		local Anim = TargetPlayer.Character.Humanoid:LoadAnimation(PinnedAnimation)
		Anim.Name = "Pinned"
		Anim:Play()
		task.wait(0.1)
		Anim:Stop()
		TargetPlayer.Character.Humanoid.WalkSpeed = 16
	end
	

end

Events.Pin.OnServerEvent:Connect(Pin)

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