Cuff system is being weird again

The system works perfectly at first, but when the player who is going to be handcuffed resets (before he is handcuffed) a weird lag effect starts. I have no idea how and why that happens can someone help out?

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")
local Remote2 = ReplicatedStorage.ExploitProtectionRemoteEvents.CuffedPlayer
local ReleaseRemote = script.Parent.ReleasePlayer
local DetainRemote = script.Parent.DetainPlayer
local ResetButtonRemote = ReplicatedStorage.ExploitProtectionRemoteEvents.DisableResetButton
local InUse = false

function PlayerCuffed(Player, Target)
	local IsPlayer = Players:GetPlayerFromCharacter(Target.Parent)
	local PlayerHasTool = Player.Backpack:FindFirstChild("Cuffs")
	if not InUse and Player.TeamColor == BrickColor.new("Really blue") then
		if Target.Name == "Torso" or Target.Name == "HumanoidRootPart" and IsPlayer ~= nil then
			local CheckDistance = (Player.Character.HumanoidRootPart.Position - Target.Position).Magnitude
			if CheckDistance <= 10 then
				local Char = Target.Parent
				local Humanoid = Char:FindFirstChild("Humanoid")
				local WeldCheck = Char.HumanoidRootPart:FindFirstChild("DetainWeld")
				if Humanoid  and WeldCheck == nil then
					Humanoid.PlatformStand = true
					local Anim = script.Parent:WaitForChild("ArrestPlayer")
					local AnimationTrack = Humanoid:LoadAnimation(Anim)
					AnimationTrack:Play()
					task.wait(0.1)
					local Weld = Instance.new("Weld")
					Weld.Name = "DetainWeld"
					Weld.Parent = Char.HumanoidRootPart
					Weld.Part0 = Player.Character.HumanoidRootPart
					Weld.Part1 = Char.HumanoidRootPart
					Weld.C1 = CFrame.new(0,0,3.5)
					local Suspect = Instance.new("StringValue")
					Suspect.Parent = Player.PlayerGui.CuffGUI
					Suspect.Name = "DetainedSuspect"
					Suspect.Value = IsPlayer.Name
					Char.Humanoid.WalkSpeed = 0
					Remote2:FireClient(Player,IsPlayer)
					ResetButtonRemote:FireClient(IsPlayer,"Disable")
					InUse = true
				end
			end
		end
	elseif Player.TeamColor ~= BrickColor.new("Really blue") then
		Player:Kick("No exploiting please!")
	end
end

function ReleasePlayer(Player, CuffedPlr)
	local Char = CuffedPlr.Character
	local SuspectValue = Player.PlayerGui.CuffGUI:WaitForChild("DetainedSuspect")
	local Weld = Char.HumanoidRootPart:WaitForChild("DetainWeld")
	Weld:Destroy()
	SuspectValue:Destroy()
	local Humanoid = Char:WaitForChild("Humanoid")
	local Anmations = Humanoid:GetPlayingAnimationTracks()
	for i, Anim in pairs(Anmations) do
		if Anim.Name == "ArrestPlayer" then
			Anim:Stop()
		end
	end
	Humanoid.PlatformStand = false
	Humanoid.WalkSpeed = 16
	InUse = false
	ResetButtonRemote:FireClient(CuffedPlr,"Enable")
end

function DetainPlayer(Player, CuffedPlr)
	local Char = CuffedPlr.Character
	local Humanoid = Char:FindFirstChild("Humanoid")
	local Weld = Char.HumanoidRootPart:WaitForChild("DetainWeld")
	Humanoid.PlatformStand = false
	Weld:Destroy()
	Humanoid.JumpPower = 0
	Humanoid.WalkSpeed = 5
	InUse = false
end

DetainRemote.OnServerEvent:Connect(DetainPlayer)
RemoteEvent.OnServerEvent:Connect(PlayerCuffed)
ReleaseRemote.OnServerEvent:Connect(ReleasePlayer)

Before Reset:

After Reset:

Have you tried setting the detained player’s character parts to massless? This might solve this issue. Though I’m not sure why this would only happen after the player resets.

2 Likes

Somehow this fixed it, still wonder why it only happened after a reset lol.

1 Like