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

How can I fix this script for cuffing a player?

So, I have created cuffs before. I tried to re-make it, and there is now an issue where when I cuff the person, they are inside of me instead of where the cuffs are supposed to be.

This is in a ServerScript inside of the tool:

--// Variables \\--
local uCP = script.Parent.UncuffPlayer
local cP = script.Parent.CuffPlayer
local jP = script.Parent.JailPlayer

--// Cuff Function \\--
cP.OnServerEvent:Connect(function(player,torso)
	local char = player.Character or player.CharacterAdded:Wait()
	
	if char then
		local charTorso = char:FindFirstChild("HumanoidRootPart")
		if charTorso then
			local cuffingVal = script.Parent.Cuffing
			cuffingVal.Value = true		
			local cuffWeld = Instance.new("Weld")
			cuffWeld.Name = "CuffWeld"
			cuffWeld.Part0 = charTorso
			cuffWeld.Part1 = torso
			cuffWeld.Parent = torso
			
			torso.CFrame = charTorso.CFrame + Vector3.new(0,0,5)			
		end
	end
end)

--// Uncuff Function \\--
uCP.OnServerEvent:Connect(function(player,torso)
	local weld = torso:FindFirstChild("CuffWeld")
	weld:Destroy()
	
	local cuffingVal = script.Parent.Cuffing
	cuffingVal.Value = false
	
	torso.Parent.Humanoid.JumpPower = 50
	torso.Parent.Humanoid.WalkSpeed = 16
end)

This is in a LocalScript inside of the tool:

--// Variables \\--
local cuffs = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

--// Equip Function \\--
cuffs.Equipped:Connect(function()
	mouse.Button1Down:Connect(function()
		if mouse.Target.Parent:FindFirstChild("Humanoid") then
			local char = mouse.Target.Parent
			if char then
				local torso = char:FindFirstChild("HumanoidRootPart")
				if torso then
					local cuffingVal = script.Parent.Cuffing
					if cuffingVal.Value == true then
						local uCP = script.Parent.UncuffPlayer
						uCP:FireServer(torso)
					else
						local cP = script.Parent.CuffPlayer
						cP:FireServer(torso)
					end
				end
			end
		end
	end)
end)

This is what my cuff looks like in the explorer:

https://gyazo.com/62245be540de83780286fbb9486f9439

1 answer

Fixed for you. I was stupid, You don't use vector3 for this simple mistake!

--// Variables \\--
local uCP = script.Parent.UncuffPlayer
local cP = script.Parent.CuffPlayer
local jP = script.Parent.JailPlayer

--// Cuff Function \\--
cP.OnServerEvent:Connect(function(player,torso)
    local char = player.Character or player.CharacterAdded:Wait()

    if char then
        local charTorso = char:FindFirstChild("HumanoidRootPart")
        if charTorso then
            local cuffingVal = script.Parent.Cuffing
            cuffingVal.Value = true     
            local cuffWeld = Instance.new("Weld")
            cuffWeld.Name = "CuffWeld"
            cuffWeld.Part0 = charTorso
            cuffWeld.Part1 = torso
            cuffWeld.Parent = torso

            torso.CFrame = charTorso.CFrame(0, 0, 5) --Fixed part
        end
    end
end)

--// Uncuff Function \\--
uCP.OnServerEvent:Connect(function(player,torso)
    local weld = torso:FindFirstChild("CuffWeld")
    weld:Destroy()

    local cuffingVal = script.Parent.Cuffing
    cuffingVal.Value = false

    torso.Parent.Humanoid.JumpPower = 50
    torso.Parent.Humanoid.WalkSpeed = 16
end)

2 comments

0

Didn't work. https://gyazo.com/90b6e0804f6240147c7bb5fbb9f3e528 - This still happens.

0

There

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