Below is a complete, drop-in solution that gives you:
• A pairing system (request → accept / decline)
• A physics rope that tethers the two players together
• A pull-up mechanic (press E when the other player is falling)
• A max-distance leash – if you walk too far you are gently stopped until your partner catches up
The code is split into two LocalScripts so it is easy to read and maintain.
Put both scripts in StarterPlayerScripts.
- PairManager (handles invites / accept / decline)
-- PairManager (LocalScript, StarterPlayerScripts)
local Players = game:GetService("Players")
local ReplicatedStorage= game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local player = Players.LocalPlayer
-- Remotes (create these once in ReplicatedStorage)
local requestPair = ReplicatedStorage:FindFirstChild("RequestPair") or Instance.new("RemoteEvent", ReplicatedStorage)
requestPair.Name = "RequestPair"
local respondPair = ReplicatedStorage:FindFirstChild("RespondPair") or Instance.new("RemoteEvent", ReplicatedStorage)
respondPair.Name = "RespondPair"
local currentPair = nil
local pendingInvite = nil
-------------------------------------------------
-- GUI for incoming invites
-------------------------------------------------
local gui = Instance.new("ScreenGui")
gui.Name = "PairInviteGui"
gui.ResetOnSpawn = false
gui.Parent = player:WaitForChild("PlayerGui")
local frame = Instance.new("Frame")
frame.Size = UDim2.new(0, 300, 0, 120)
frame.Position = UDim2.new(0.5, -150, 0.5, -60)
frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
frame.BorderSizePixel = 0
frame.Visible = false
frame.Parent = gui
local title = Instance.new("TextLabel")
title.Size = UDim2.new(1, 0, 0.4, 0)
title.BackgroundTransparency = 1
title.TextColor3 = Color3.new(1, 1, 1)
title.Font = Enum.Font.SourceSansBold
title.TextScaled = true
title.Parent = frame
local accept = Instance.new("TextButton")
accept.Size = UDim2.new(0.45, 0, 0.5, 0)
accept.Position = UDim2.new(0.025, 0, 0.45, 0)
accept.Text = "Accept"
accept.BackgroundColor3 = Color3.fromRGB(0, 170, 0)
accept.TextScaled = true
accept.Parent = frame
local decline = accept:Clone()
decline.Position = UDim2.new(0.525, 0, 0.45, 0)
decline.Text = "Decline"
decline.BackgroundColor3 = Color3.fromRGB(170, 0, 0)
decline.Parent = frame
-------------------------------------------------
-- Functions
-------------------------------------------------
local function showInvite(from)
if pendingInvite then return end
pendingInvite = from
title.Text = ("%s wants to pair!"):format(from.Name)
frame.Visible = true
end
local function hideInvite()
pendingInvite = nil
frame.Visible = false
end
accept.MouseButton1Click:Connect(function()
if pendingInvite then
respondPair:FireServer(pendingInvite, true)
end
hideInvite()
end)
decline.MouseButton1Click:Connect(function()
if pendingInvite then
respondPair:FireServer(pendingInvite, false)
end
hideInvite()
end)
-------------------------------------------------
-- Request pairing (press R)
-------------------------------------------------
UIS.InputBegan:Connect(function(inp, gp)
if gp then return end
if inp.KeyCode == Enum.KeyCode.R then
-- Raycast to find closest player
local closest, dist = nil, math.huge
local myRoot = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
if not myRoot then return end
for _,plr in ipairs(Players:GetPlayers()) do
if plr ~= player and plr.Character then
local root = plr.Character:FindFirstChild("HumanoidRootPart")
if root then
local d = (root.Position - myRoot.Position).Magnitude
if d < 15 and d < dist then
closest, dist = plr, d
end
end
end
end
if closest then
requestPair:FireServer(closest)
end
end
end)
-------------------------------------------------
-- Listen for incoming invites
-------------------------------------------------
requestPair.OnClientEvent:Connect(showInvite)
-------------------------------------------------
-- When server tells us we are paired / unpaired
-------------------------------------------------
respondPair.OnClientEvent:Connect(function(other, accepted)
if accepted then
currentPair = other
script:WaitForChild("RopeHandler"):Clone().Parent = script -- start rope
else
currentPair = nil
end
end)
- RopeHandler (LocalScript, parented by PairManager when paired)
-- RopeHandler (LocalScript, child of PairManager)
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local pairPlayer = script:GetAttribute("PairPlayer") -- set by server (or just use currentPair)
-- Wait for pairPlayer to be set (or grab from PairManager)
while not pairPlayer do
wait()
pairPlayer = script.Parent.Parent:FindFirstChild("PairManager") and
script.Parent.Parent.PairManager:FindFirstChild("currentPair") and
script.Parent.Parent.PairManager.currentPair.Value
end
-------------------------------------------------
-- Create rope visuals
-------------------------------------------------
local rope = Instance.new("RopeConstraint")
rope.Visible = true
rope.Color = BrickColor.new("Brown")
rope.Thickness = 0.3
rope.Parent = workspace
local att0 = Instance.new("Attachment")
local att1 = Instance.new("Attachment")
att0.Parent = player.Character:WaitForChild("HumanoidRootPart")
att1.Parent = pairPlayer.Character:WaitForChild("HumanoidRootPart")
rope.Attachment0 = att0
rope.Attachment1 = att1
-------------------------------------------------
-- Constants
-------------------------------------------------
local MAX_DIST = 25
local PULL_DIST = 40
local PULL_FORCE = 2000
-------------------------------------------------
-- Pull-up mechanic
-------------------------------------------------
local function pullPartner()
if not pairPlayer.Character then return end
local myRoot = player.Character:FindFirstChild("HumanoidRootPart")
local theirRoot = pairPlayer.Character:FindFirstChild("HumanoidRootPart")
if not (myRoot and theirRoot) then return end
local dist = (myRoot.Position - theirRoot.Position).Magnitude
if dist > PULL_DIST then return end -- too far to pull
local dir = (myRoot.Position - theirRoot.Position).Unit
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(PULL_FORCE, PULL_FORCE, PULL_FORCE)
bv.Velocity = dir * 30
bv.Parent = theirRoot
game:GetService("Debris"):AddItem(bv, 0.3)
end
UIS.InputBegan:Connect(function(inp, gp)
if gp then return end
if inp.KeyCode == Enum.KeyCode.E then
pullPartner()
end
end)
-------------------------------------------------
-- Distance leash
-------------------------------------------------
local function clampDistance()
if not pairPlayer.Character then return end
local myRoot = player.Character:FindFirstChild("HumanoidRootPart")
local theirRoot = pairPlayer.Character:FindFirstChild("HumanoidRootPart")
if not (myRoot and theirRoot) then return end
local dist = (myRoot.Position - theirRoot.Position).Magnitude
if dist > MAX_DIST then
local dir = (theirRoot.Position - myRoot.Position).Unit
local target = theirRoot.Position - dir * MAX_DIST
myRoot.CFrame = CFrame.new(target)
end
end
RunService.Heartbeat:Connect(clampDistance)
-------------------------------------------------
-- Clean-up when unpaired / character dies
-------------------------------------------------
local function cleanup()
rope:Destroy()
script:Destroy()
end
player.CharacterRemoving:Connect(cleanup)
pairPlayer.CharacterRemoving:Connect(cleanup)
- Server-side glue (Script, ServerScriptService)
-- PairServer (Script, ServerScriptService)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local requestPair = ReplicatedStorage:WaitForChild("RequestPair")
local respondPair = ReplicatedStorage:WaitForChild("RespondPair")
local pairs = {} -- [player] = other
requestPair.OnServerEvent:Connect(function(from, to)
if pairs[from] or pairs[to] then return end -- already paired
requestPair:FireClient(to, from)
end)
respondPair.OnServerEvent:Connect(function(from, to, accepted)
if accepted then
pairs[from] = to
pairs[to] = from
respondPair:FireClient(from, to, true)
respondPair:FireClient(to, from, true)
else
respondPair:FireClient(from, to, false)
end
end)
-- auto-unpair on leave
game.Players.PlayerRemoving:Connect(function(plr)
local other = pairs[plr]
if other then
pairs[other] = nil
respondPair:FireClient(other, nil, false)
end
pairs[plr] = nil
end)
How to use
- Create the RemoteEvents
RequestPair and RespondPair inside ReplicatedStorage once.
- Drop the PairManager LocalScript into StarterPlayerScripts.
- Drop the RopeHandler LocalScript into PairManager (it will clone itself automatically).
- Drop the PairServer Script into ServerScriptService.
In-game:
• Press R while standing near another player to send a pairing request.
• The other player sees a GUI with Accept / Decline.
• Once paired, a brown rope appears between the two HumanoidRootParts.
• If one player falls, the other can press E to pull them up.
• If you try to walk farther than MAX_DIST studs, you are gently stopped until your partner gets closer.