collar handler script:
local events = game.ReplicatedStorage:WaitForChild("RemoteEvents")

-- Store a reference to the active collars
local activeCollars = {}

local function GiveCollarGetAttachment(player)
	local char = player.Character
	local g = script.Collar:Clone()
	g.Parent = char

	local C = g:GetChildren()
	for i = 1, #C do
		if C[i]:IsA("BasePart") then
			local W = Instance.new("Weld")
			W.Part0 = g.Middle
			W.Part1 = C[i]
			local CJ = CFrame.new(g.Middle.Position)
			local C0 = g.Middle.CFrame:Inverse() * CJ
			local C1 = C[i].CFrame:Inverse() * CJ
			W.C0 = C0
			W.C1 = C1
			W.Parent = g.Middle
		end
	end

	local Y = Instance.new("Weld")
	Y.Part0 = char.Head
	Y.Part1 = g.Middle
	Y.C0 = CFrame.new(0, 0, 0)
	Y.Parent = Y.Part0

	local h = g:GetChildren()
	for i = 1, #h do
		if h[i]:IsA("BasePart") then
			h[i].Anchored = false
			h[i].CanCollide = false
		end
	end

	return g.AttachmentPart.Attachment
end

local function AddAttachmentToArm(player)
	local char = player.Character
	local newAttachment = Instance.new("Attachment")
	newAttachment.Position = Vector3.new(0, -1, 0)
	newAttachment.Parent = char["Right Arm"]

	return newAttachment
end

local function MakeLeash(Attachment0, Attachment1)
	local newRopeRenderer = script.RopeRenderer:Clone()
	newRopeRenderer.DrawLocalLine.Attachment0.Value = Attachment0
	newRopeRenderer.DrawLocalLine.Attachment1.Value = Attachment1
	newRopeRenderer.DrawLocalLine.RemoveEvent.Value = newRopeRenderer.RemoveCollar
	newRopeRenderer.Parent = workspace
	newRopeRenderer.Disabled = false

	return newRopeRenderer
end

local function AddPlayerController(victim, owner, removeEvent)
	local newPlayerController = script.PlayerController:Clone()
	newPlayerController.Owner.Value = owner.Character
	newPlayerController.RemoveEvent.Value = removeEvent
	newPlayerController.Parent = victim.PlayerGui
	newPlayerController.Disabled = false

	return newPlayerController
end

local function AddCollarRemover(victim, owner, removeEvent)
	local newRemover = script.CollarRemover:Clone()
	newRemover.RemoveEvent.Value = removeEvent
	newRemover.Victim.Value = victim
	newRemover.Owner.Value = owner
	newRemover.Parent = workspace
	newRemover.Disabled = false

	return newRemover
end

local function RemoveCollar(victim, remover)
	print("Removing collar for victim:", victim.Name, "by remover:", remover.Name)

	-- Check and remove components from the victim's character
	if activeCollars[victim] then
		local collarData = activeCollars[victim]

		-- Debugging: Check components before removal
		print("Removing collar for:", victim.Name)
		print("Rope exists:", collarData.rope and collarData.rope.Parent)
		print("Controller exists:", collarData.controller and collarData.controller.Parent)
		print("Remover exists:", collarData.remover and collarData.remover.Parent)

		-- Ensure each component exists before trying to destroy it
		if collarData.rope and collarData.rope.Parent then
			print("Destroying rope...")
			collarData.rope:Destroy()
		end

		if collarData.controller and collarData.controller.Parent then
			print("Destroying controller...")
			collarData.controller:Destroy()
		end

		if collarData.remover and collarData.remover.Parent then
			print("Destroying remover...")
			collarData.remover:Destroy()
		end

		for _, part in pairs(victim.Character:GetChildren()) do
			if part:IsA("BasePart") and part.Name == "LineSegments" then
				print("Destroying line segment part...")
				part:Destroy()
			end
		end

		local collarModel = victim.Character:FindFirstChild("Collar")
		if collarModel then
			print("Destroying collar model...")
			collarModel:Destroy()
		end

		-- Clear the activeCollars entry for the victim
		activeCollars[victim] = nil
		print("Collar removed successfully!")

		-- Notify the remover and victim about the collar update
		events.UpdateCollarButton:FireClient(remover, "Request Collar")
		events.UpdateCollarButton:FireClient(victim, "Request Collar")
	else
		print("No collar found for:", victim.Name)
		events.UpdateCollarButton:FireClient(remover, "Request Collar")
	end

	-- Also remove LineSegments from the remover's character if any
	for _, part in pairs(remover.Character:GetChildren()) do
		if part:IsA("BasePart") and part.Name == "LineSegments" then
			print("Destroying line segment part from remover...")
			part:Destroy()
		end
	end
end


events.RemoveCollar.OnServerEvent:Connect(function(player, target)
	if target then
		print("RemoveCollar event received for:", target.Name)
		if activeCollars[target] then
			-- target is the victim needing their collar removed
			RemoveCollar(target, player)
		elseif activeCollars[player] then
			-- fallback in case the active one is the player
			RemoveCollar(player, target)
		else
			print("Neither player has an active collar")
		end
	else
		print("No valid target received in RemoveCollar event")
	end
end)


local function MakeCollar(owner, victim)
	print("Creating collar: Owner:", owner.Name, "Victim:", victim.Name)
	local attachment0 = GiveCollarGetAttachment(victim)
	local attachment1 = AddAttachmentToArm(owner)
	local newRope = MakeLeash(attachment0, attachment1)

	local newController = AddPlayerController(victim, owner, newRope.RemoveCollar)
	local newRemover = AddCollarRemover(victim, owner, newRope.RemoveCollar)

	activeCollars[victim] = {
		rope = newRope,
		controller = newController,
		remover = newRemover
	}

	print("Collar created for:", victim.Name)
	print("activeCollars table:", activeCollars)

	events.UpdateCollarButton:FireClient(owner, "Remove Collar")
	events.UpdateCollarButton:FireClient(victim, "Remove Collar")
end

events.SendCollarRequest.OnServerEvent:Connect(function(player, target)
	events.ActivateLocalCollarUI:FireClient(target, player.Name)
end)

events.CollarPlayer.OnServerEvent:Connect(function(victim, owner)
	MakeCollar(owner, victim)
end)


collar remover script parented to the collar handler:
local victim = script.Victim.Value
local owner = script.Owner.Value

function RemoveCollar(VictimHasDied)
	print("Removing collar")
	script:WaitForChild("RemoveEvent").Value:FireAllClients()

	--ResetAnimation
	if VictimHasDied then
		if victim and victim.Character then

			local character = victim.Character
			local animationScript = character:WaitForChild("Animate")

			animationScript.idle.Animation1.AnimationId = "rbxassetid://180435571"
			animationScript.idle.Animation2.Weight.Value = 1

			animationScript.jump.JumpAnim.AnimationId = "rbxassetid://125750702"
			animationScript.fall.FallAnim.AnimationId = "rbxassetid://180436148"

			animationScript.run.RunAnim.AnimationId = "rbxassetid://180426354"
			animationScript.walk.WalkAnim.AnimationId = "rbxassetid://180426354"
		end
	end
	--
	if victim.Character then
		victim.Character.Collar:Destroy()
	end
	script:Destroy()
end

function OnVictimDeath()
	RemoveCollar(true)
end

function OnOwnerDeath()
	RemoveCollar(false)
end

victim.Character.Humanoid.Died:Connect(OnVictimDeath)
owner.Character.Humanoid.Died:Connect(OnOwnerDeath)

victim.CharacterRemoving:Connect(OnVictimDeath)
owner.CharacterRemoving:Connect(OnOwnerDeath)

rope renderer script parented to the collar handler:
local replicatedScripts = {}
local JoinReplicateConnection

function StartCurveReplication()
	
	JoinReplicateConnection = game.Players.PlayerAdded:Connect(function(player)
		coroutine.resume(coroutine.create(function()
			local replicatedCurve = script.DrawLocalLine:Clone()
			replicatedCurve.Parent = player.PlayerGui
			table.insert(replicatedScripts, replicatedCurve)
			replicatedCurve.Disabled = false
		end))
	end)
	
	for i, v in game.Players:GetPlayers() do
		coroutine.resume(coroutine.create(function()
			local replicatedCurve = script.DrawLocalLine:Clone()
			replicatedCurve.Parent = v.PlayerGui
			table.insert(replicatedScripts, replicatedCurve)
			replicatedCurve.Disabled = false
		end))
	end
	
end

StartCurveReplication()

script.RemoveCollar.OnServerEvent:Connect(function()
	JoinReplicateConnection:Disconnect()
	script:Destroy()
end)

when one of the players use the 'remove collar' button there is still some LineSegment parts remaining in workspace, attached to the owner's right arm.