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!
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?
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
Hey! I made something similar, lemme show you the script! hope this helps
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