Trying to make a toggleable rope (attach/detach)

im trying to attach/detach a rope, something like flee the facility from the character. so it’ll attach/detach from the two characters but i cant get the toggle to work.
localscript:

local event = game.ReplicatedStorage:WaitForChild("ropeEvent")
local plr = game.Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()

mouse.Button1Down:Connect(function()
	local mouseTarget = mouse.Target
	
	local target = mouseTarget:FindFirstAncestorOfClass("Model")
	local player = game.Players:GetPlayerFromCharacter(target)
	local otherchar = player.Character
	
	if player then

	print("rope is on")
			event:FireServer(otherchar)
	end
end)

script:

event.OnServerEvent:Connect(function(plr, otherchar)
	local rope
	local at0
	local at1
	local mychar = plr.Character
	local otherplr:Player = game.Players:GetPlayerFromCharacter(otherchar)
	local ropeOn = nil
	

	if mychar.Humanoid.Health == 0 or otherchar.Humanoid.Health == 0 then return end

	local parts = {
		"charRope"
	}

	for _, part in ipairs(mychar:GetDescendants()) do
		if table.find(parts, part.Name) then return end
	end

if ropeOn == nil then
				 rope = Instance.new("RopeConstraint", mychar)
				rope.Name = "charRope"
				rope.Visible = true
				rope.Thickness = .15
				at0 = Instance.new("Attachment", mychar.RightHand)
				at0.Name = "at0"
				at1 = Instance.new("Attachment", otherchar.HumanoidRootPart)
				at1.Name = "at1"
				rope.Attachment0 = at0
				rope.Attachment1 = at1
				rope.Length = 10
				rope.Color = BrickColor.new("Really red")
				ropeOn = true
if ropeOn then
rope:Destroy()
at1:Destroy()
at0:Destroy()
end
end
end)

Is your script throwing any errors? Have you tried logging?

1 Like

hey mocha, thanks 4 the response. :slight_smile:

ive never used breakpoints/logpoints before so im pretty new to debugging but i tried putting a breakpoint + a logpoint in my code and its not stopping for debugging.

https://gyazo.com/a321ecb9b9f9cd8f58ebd57983b72ac2