Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Handcuff script is making my player not be able to move?

local RemoteEvent = script.Parent.RemoteEvent
local Using = false
local TargetTorso
local weld

function CheckForChar(Part)
	if Part.Parent:IsA('Model') and Part.Parent:FindFirstChildOfClass('Humanoid') then
		local Char = Part.Parent
		TargetTorso = Char:WaitForChild("HumanoidRootPart") 
		return Char
	end
end

function CheckForTorso(player)
	local Char = player.Character
	if Char:FindFirstChild('Torso') then
		return Char.Torso
	else 
		return Char.UpperTorso
	end
end

RemoteEvent.OnServerEvent:Connect(function(player, one, two)
	if one == 'Cuff' then
		local Target = CheckForChar(two)		
		local PlayerTorso = CheckForTorso(player)
		
		if Target then
			Using = true
			RemoteEvent:FireClient(player,'Use') 

			weld = Instance.new("Weld")
			weld.Part0 = PlayerTorso
			weld.Part1 = TargetTorso
			weld.C0 = CFrame.new(0,0,-3.5)
			weld.Parent = PlayerTorso
		end
	elseif one == 'UnCuff'then
		Using = false		
		weld:Destroy()
	end
end)

For some reason the player who got cuffed is able to move very slowly while the person using the cuffs can't move at all, anyone know how I could fix this?

3 comments

0

Is anything anchored?

0

No, I don't think so. I don't have anything being anchored or unanchored

0

You might have a part inside the handcuff model that is anchored without realizing it

1 answer

✓ Accepted answer

It looks like what you're doing here is welding two different players' characters together. This won't work because of network ownership. One set of connected parts must have the same network owner, and by default every player has ownership of their own character. When you connect the two characters, the players can't be in control of their own characters anymore.

A workaround for this that avoids joining the two characters physically would be to use a BodyPosition in each character, keeping the Position properties updated so they are attracted together, and increasing the MaxForce proportionally to the square of their distance like a spring.

This discussion is preserved as it was. New answers, comments, and votes are closed.