Help Needed. An Arrest/Release Tool I have created which breaks when I add a weld

Hello!, I am creating an arrest tool which allows for a player with to tool to arrest other players and move them around with the help of a weld. I have successfully completed most of this except for the welding which allows you to move the other character around. I have attempted to solve this by placing print(" ") around the script to find out the problem and the problem is the hit function, for some reason, the script works perfectly without the weld creator, you are able to arrest the character, but are not able to release them after. This is the script I have created, the two top lines are to detect if the tool has been activated from a local script:

Toggle = false
ToggleB = true
script.Parent.RemoteEvent.OnServerEvent:Connect(function()
local animationTrack = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Action)
	animationTrack:Play(nil, nil, 1)
	Toggle = true
	wait(1)
	Toggle = false
end)

script.Parent.Arrest.OnServerEvent:Connect(function()
	if ToggleB == true then
		ToggleB = false
		print("false")
	else
	if ToggleB == false then
		ToggleB = true
		print("true")
		end
	end
end)

script.Parent.Handle.Touched:Connect(function(hit)
local animationTrack = hit.Parent.Humanoid:LoadAnimation(script.Parent.Animation)
print("Hit")
	if hit.Parent.Humanoid ~= nil then
		print("Human")
		if Toggle == true then
			print("Tog")
			if ToggleB == true then
				print("Arrest")
				hit.Parent.Humanoid.WalkSpeed = 6
				hit.parent.Humanoid:UnequipTools()
				animationTrack:Play(nil, nil, 0)

				local weld = Instance.new("Weld")
				weld.Parent = script.Parent.Parent.Torso
				weld.Part0 = script.Parent.Parent.Torso
				weld.Part1 = hit.Parent.Torso
				weld.C0 = CFrame.new(0,1,-1)

			elseif ToggleB == false then
				print("Release")
				hit.Parent.Humanoid.WalkSpeed = 16
				animationTrack:Stop()
			end
		end
	end
end)

If someone could find or explain what is wrong with this part of the script it would be much appreciated. Thank you!

Did you get any errors in the output or unintended behavior with your code?

No, I have checked it but there is nothing declaring that there are errors present.

Is this script in the startercharacterscripts? If it’s not, then that might be the reason that your script isn’t working.

The localscript is fine in the tool, because local scripts can run in tools. Also, is it that the players are not moving? Are you sure you checked the entire output?

I apologise, I had not specified how the script breaks.

works perfectly without the weld creator, you are able to arrest the victim character, but are not able to release them after.

I apologize for not explaining how the tool breaks,

works perfectly without the weld creator, you are able to arrest the character, but are not able to release them after.

The script being displayed is a script inside of the tool. It is not local, but it is controlled by a local script.

Have you tried destroying the weld?

I am not too familiar with welding, would It still weld the player if I used the weld codes in a local script?

local weld = Instance.new(“Weld”)
weld.Parent = script.Parent.Parent.Torso
weld.Part0 = script.Parent.Parent.Torso
weld.Part1 = hit.Parent.Torso
weld.C0 = CFrame.new(0,1,-1)

It probably won’t because the weld is created locally, so it won’t replicate to the server. The victim might be welded to the player whom arrested him on their screen, but on the victim’s screen, the victim probably won’t be welded. So the weld has to be created on the served

I have fixed the tool by using a CFrame offset to the player instead of a weld and now it works perfectly.
while ToggleB and wait() do
hit.Parent.Torso.CFrame = script.Parent.Parent.Torso.CFrame * CFrame.new( 0, 0, -5)
end

1 Like

Hey! I made something similar, lemme show you the script! hope this helps :slight_smile:

function PinPlayer(Pinner, Pinned)
	if not Pinned.Character:FindFirstChild("Pinned")  then
	local Value = Instance.new("ObjectValue", Pinned.Character)
	Value.Name = "Pinned"
tarr = Pinned
off = Pinner
	Pinned.Character.Humanoid.PlatformStand = true
	local aw = Pinned.Character.Humanoid:LoadAnimation(PinnedAnim)
	local Value2 = Instance.new("StringValue", Pinner.Character)
	Value2.Name = "Grabbing"
	aw:Play()
	Pinned.PlayerGui.Backpack.Enabled = false
	Pinned.PlayerGui.Backpack.Frame.LocalScript.Disabled = true
  local Weld = Instance.new("Weld", Pinner.Character)
	Weld.Name = "InteractWeld"
	Weld.Part0 = Pinner.Character.HumanoidRootPart
	Weld.Part1 = Pinned.Character.HumanoidRootPart
	Value.Value = Weld
	Value2.Value = Pinned.Name
	Pinned.Character.Humanoid:UnequipTools()
	Weld.C1 = CFrame.new(0,0,2.5)
	elseif Pinned.Character:FindFirstChild("Pinned") or Pinner.Character:FindFirstChild("InteractWeld")  then
			for i,v in pairs(Pinned.Character.Humanoid:GetPlayingAnimationTracks()) do
		v:Stop()
			end
			tarr = nil
off = nil
		 if Pinned.Character:FindFirstChild("Pinned") then
			Pinned.Character:FindFirstChild("Pinned"):Destroy()
		end
	   if Pinner.Character:FindFirstChild("Grabbing") or Pinner.Character:FindFirstChild("InteractWeld") or Pinned.Character:FindFirstChild("Pinned") then
		for i,v in pairs(Pinner.Character:GetChildren()) do
			if v.Name == "Pinned" or v.Name == "Grabbing" or v.Name == "InteractWeld" then
				v:Destroy()
			end
		 		end
		for i,v in pairs(Pinned.Character:GetChildren()) do
			if v.Name == "Pinned" or v.Name == "Grabbing" or v.Name == "InteractWeld" then
				v:Destroy()
			end
 		end
	end
		Pinned.Character.Humanoid.WalkSpeed = 16
		Pinned.PlayerGui.Backpack.Enabled = true
		Pinned.PlayerGui.Backpack.Frame.LocalScript.Disabled = false
	   Pinned.Character.Humanoid.PlatformStand = false
	

	for i,v in pairs(Pinned.Character.Humanoid:GetPlayingAnimationTracks()) do
		v:Stop()
	end
	
	end
end
3 Likes