serverscript:
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)
	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

		activeCollars[victim] = nil
		print("Collar removed successfully!")

		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
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)
		else
			-- fallback in case the active one is the player
			RemoveCollar(player, target)
		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)

localscript that handles the collar button:
local Player = game.Players.LocalPlayer
local pgui = Player.PlayerGui

local mouse = Player:GetMouse()
local target = nil

local UI = script.Parent
local Main = UI.Frame
local intmenu = Main.OptionStuff
local cam = workspace.CurrentCamera

function HideUI()
	Main.TitleLabel.Text = ""
	Main.Visible = false
end

function button1Down()
	if not mouse.Target then
		target = nil
		HideUI()
	else
		if mouse.Target.Parent:FindFirstChild("Humanoid")
			and mouse.Target.Parent:FindFirstChild("HumanoidRootPart") then
			if game.Players:FindFirstChild(mouse.Target.Parent.Name) then
				target = mouse.Target.Parent:FindFirstChild("HumanoidRootPart")
				Main.TitleLabel.Text = mouse.Target.Parent.Name .. " Sync Menu:"
				intmenu.PlayerName.Value = mouse.Target.Parent.Name
			else
				target = nil
				HideUI()
			end
		else
			target = nil
			HideUI()
		end
	end	
end

mouse.Button1Down:Connect(button1Down)

function findPlayer(name)
	for _, player in pairs(game.Players:GetPlayers()) do
		if string.lower(player.Name) == string.lower(name) then
			return player
		end
	end
	return nil
end


intmenu.Button1.MouseButton1Click:Connect(function()
	local a = findPlayer(intmenu.PlayerName.Value)
	if a and a ~= game.Players.LocalPlayer then
		if pgui:FindFirstChild("Syncs") then
			if pgui.Syncs:FindFirstChild(a.Name) then
				game.ReplicatedStorage.RemoteEvents.RemoveSync:FireServer(a)
			else
				game.ReplicatedStorage.RemoteEvents.SendSyncRequest:FireServer(a)
			end
		end
	end
end)

intmenu.Button2.MouseButton1Click:Connect(function()
	local target = findPlayer(intmenu.PlayerName.Value)
	if target then
		if intmenu.Button2.Text == "Request Collar" then
			game.ReplicatedStorage.RemoteEvents.SendCollarRequest:FireServer(target)
		elseif intmenu.Button2.Text == "Remove Collar" then
			print("Attempting to remove collar from:", target.Name)
			game.ReplicatedStorage.RemoteEvents.RemoveCollar:FireServer(Player, target)
		end
	end
end)



game["Run Service"].Stepped:Connect(function()
	if target ~= nil then
		local vector, onScreen = cam:WorldToScreenPoint(target.Position)
		local screenPoint = Vector2.new(vector.X, vector.Y)
		local depth = vector.Z

		intmenu.Button1.Text = "Request Sync"
		intmenu.Button1.TextColor3 = Color3.fromRGB(162, 255, 162)

		if pgui:FindFirstChild("Syncs") then
			if pgui.Syncs:FindFirstChild(intmenu.PlayerName.Value) then
				intmenu.Button1.Text = "Un-Sync"
				intmenu.Button1.TextColor3 = Color3.fromRGB(255, 162, 162)
			end
		end 

		Main.Position = UDim2.new(0, screenPoint.X, 0, screenPoint.Y)
		if onScreen then
			Main.Visible = true
		else
			Main.Visible = false
		end
	else
		HideUI()
	end
end)

game.ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("ActivateLocalSyncUI").OnClientEvent:Connect(function(a)
	local newsync = script.Parent.SyncNotif:Clone()
	newsync.PlayerName.Value = a
	newsync.TextLabel.Text = a .. " would like to sync."
	newsync.Visible = true
	print("this works properly?")
	newsync.Parent = UI.Frame1
end)

game.ReplicatedStorage.RemoteEvents.UpdateCollarButton.OnClientEvent:Connect(function(newText)
	intmenu.Button2.Text = newText
	if newText == "Remove Collar" then
		intmenu.Button2.TextColor3 = Color3.fromRGB(255, 0, 0) -- Red color
	else
		intmenu.Button2.TextColor3 = Color3.fromRGB(255, 255, 255) -- White color
	end
end)

localscript that handles what happesn when the player presses 'Accept' to the player's collar request:
script.Parent.MouseButton1Click:Connect(function()
	local requester = game.Players:FindFirstChild(script.Parent.Parent.PlayerName.Value)
	if requester then
		game.ReplicatedStorage.RemoteEvents.CollarPlayer:FireServer(requester)
	end
	
	script.Parent.Parent.Visible = false
end)

if the person that got collared presses the 'Remove Collar' button, everything handles well. if the person that initiated the collaring presses the 'Remove Collar' button, nothing happens. give me the code i have to modify, don't give me the whole codes again.