Advertisement
KrYn0MoRe

Hold Character [Tool]

Aug 22nd, 2023 (edited)
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.47 KB | None | 0 0
  1. local plr = owner
  2. local char = plr.Character
  3. local root = char:FindFirstChild("HumanoidRootPart") or char:FindFirstChild("Torso") or char:FindFirstChild("UpperTorso")
  4. local bp = plr.Backpack
  5.  
  6. local tool = Instance.new("Tool")
  7. tool.Name = 'Hold Character'
  8. tool.ToolTip = 'Click with arm on someone to capture!'
  9. tool.CanBeDropped = false
  10. tool.Parent = bp
  11.  
  12. local h = Instance.new("Part")
  13. h.Name = 'Handle'
  14. h.Size = Vector3.new(2,6,2)
  15. h.Transparency = 1
  16. h.Anchored = false
  17. h.Massless = true
  18. h.CanCollide = false
  19. h.Parent = tool
  20.  
  21. local network_loop,char_loop,captured
  22.  
  23. function is_captured()
  24.     if captured and captured[1] and captured[2] and captured[3] and captured[2].Parent then
  25.         return true
  26.     end
  27. end
  28.  
  29. function release()
  30.     if captured[1] then
  31.         captured[1]:Destroy()
  32.     end
  33.  
  34.     if captured[3] then
  35.         captured[3].PlatformStand = false
  36.     end
  37.    
  38.     local nl = network_loop ~= nil
  39.    
  40.     if network_loop then
  41.         network_loop:Disconnect()
  42.         network_loop = nil
  43.     end
  44.     if char_loop then
  45.         char_loop:Disconnect()
  46.         char_loop = nil
  47.     end
  48.  
  49.     if captured[2] and captured[2].Parent then
  50.         for i,v in pairs(captured[2]:GetDescendants()) do
  51.             if v:IsA("BasePart") then
  52.                 if nl and v.Parent == captured[2] then
  53.                     v:SetNetworkOwnershipAuto()
  54.                 end
  55.                 v.CollisionGroupId = 0
  56.                 v.Massless = false
  57.             end
  58.         end
  59.     end
  60.    
  61.     tool.Name = 'Hold [N/A]'
  62.     captured = nil
  63. end
  64.  
  65. function perish()
  66.     if is_captured() then else return end
  67. end
  68.  
  69. function throw()
  70.     if is_captured() then else return end
  71.     local tchar = captured[2]
  72.     local troot = tchar:FindFirstChild("HumanoidRootPart") or tchar:FindFirstChild("Torso") or tchar:FindFirstChild("UpperTorso")
  73.    
  74.     release()
  75.    
  76.     local bv = Instance.new("BodyVelocity")
  77.     bv.MaxForce = Vector3.new(1/0,1/0,1/0)
  78.     bv.Velocity = root.CFrame.LookVector*40+Vector3.new(0,5,0)
  79.     bv.Parent = troot
  80.     game:GetService("Debris"):AddItem(bv,0.2)
  81. end
  82.  
  83. tool.Unequipped:Connect(function()
  84.     release()
  85. end)
  86.  
  87. local r = Instance.new("RemoteEvent")
  88. r.Parent = char
  89.  
  90. r.OnServerEvent:Connect(function(lplr,key)
  91.     if lplr == plr then else return end
  92.     if key == Enum.KeyCode.Q then
  93.         perish()
  94.     elseif key == Enum.KeyCode.E then
  95.         throw()
  96.     end
  97. end)
  98.  
  99. NLS([[
  100. local plr = game:GetService("Players").LocalPlayer
  101. local r = script.Parent
  102. local uis = game:GetService("UserInputService")
  103.  
  104. uis.InputBegan:Connect(function(input,gp)
  105.     if gp then return end
  106.     if input.UserInputType == Enum.UserInputType.Keyboard then
  107.         local key = input.KeyCode
  108.         r:FireServer(key)
  109.     end
  110. end)
  111. ]],r)
  112.  
  113. tool.Activated:Connect(function()
  114.     local olp = OverlapParams.new()
  115.     olp.MaxParts = 0
  116.     olp.FilterType = Enum.RaycastFilterType.Exclude
  117.     olp.FilterDescendantsInstances = {char,tool}
  118.  
  119.     if captured then
  120.         release()
  121.  
  122.         return
  123.     end
  124.  
  125.     local p = workspace:GetPartBoundsInBox(h.CFrame,h.Size,olp)
  126.     for i,v in ipairs(p) do
  127.         local tchar = v:FindFirstAncestorOfClass("Model")
  128.         if tchar then else continue end
  129.         local tplr = game:GetService("Players"):GetPlayerFromCharacter(tchar)
  130.         local thum = tchar:FindFirstChildOfClass("Humanoid")
  131.         local troot = tchar:FindFirstChild("HumanoidRootPart") or tchar:FindFirstChild("Torso") or tchar:FindFirstChild("UpperTorso")
  132.         if thum and thum.Health > 0 and troot then else continue end
  133.  
  134.         if tplr then
  135.             local tbp = tplr:FindFirstChildOfClass("Backpack")
  136.  
  137.             for i,o in pairs(tchar:GetChildren()) do
  138.                 if o:IsA("Tool") then
  139.                     thum:UnequipTools()
  140.                 end
  141.             end
  142.  
  143.             char_loop = tchar.ChildAdded:Connect(function(o)
  144.                 if o:IsA("Tool") then
  145.                     thum:UnequipTools()
  146.                 end
  147.             end)
  148.  
  149.             network_loop = game:GetService("RunService").Heartbeat:Connect(function()
  150.                 if tchar and tchar.Parent and plr then else
  151.                     char_loop:Disconnect()
  152.                     network_loop:Disconnect()
  153.                     network_loop = nil
  154.                     char_loop = nil
  155.                     return
  156.                 end
  157.  
  158.                 thum:UnequipTools()
  159.                 thum:ChangeState(Enum.HumanoidStateType.GettingUp)
  160.                 thum.PlatformStand = true
  161.                
  162.                 for i,v in ipairs(tchar:GetDescendants()) do
  163.                     if v:IsA("BasePart") then
  164.                         if v.Parent == tchar then
  165.                             v:SetNetworkOwner(plr)
  166.                         end
  167.                         v.Massless = true
  168.                     end
  169.                 end
  170.             end)
  171.         end
  172.  
  173.         thum:ChangeState(Enum.HumanoidStateType.GettingUp)
  174.         thum.PlatformStand = true
  175.  
  176.         local weld = Instance.new("Weld")
  177.         weld.Part0 = h
  178.         weld.Part1 = troot
  179.         weld.Parent = h
  180.  
  181.         for i,v in ipairs(tchar:GetDescendants()) do
  182.             if v:IsA("BasePart") then
  183.                 v.Massless = true
  184.             end
  185.         end
  186.  
  187.         tool.Name = tchar.Name
  188.         captured = {weld,tchar,thum}
  189.  
  190.         break
  191.     end
  192. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement