HowToRoblox

ObjectMover

Jul 26th, 2021 (edited)
3,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. game.ReplicatedStorage:WaitForChild("OnGrabRE").OnServerEvent:Connect(function(plr, target, dropping)
  2.    
  3.     if not target then return end
  4.    
  5.    
  6.     if dropping then
  7.        
  8.        
  9.         target:SetNetworkOwner(nil)
  10.        
  11.        
  12.         for i, child in pairs(target:GetChildren()) do
  13.            
  14.             if child:IsA("BodyGyro") or child:IsA("BodyPosition") then
  15.                
  16.                 child:Destroy()
  17.             end
  18.         end
  19.        
  20.         target.CanGrab.Value = ""
  21.    
  22.    
  23.     elseif target:FindFirstChild("CanGrab") and target.CanGrab.Value == "" then
  24.        
  25.        
  26.         local distance = (plr.Character.HumanoidRootPart.Position - target.Position).Magnitude
  27.        
  28.         if distance > 15 then return end
  29.        
  30.        
  31.         target.CanGrab.Value = plr.Name
  32.        
  33.        
  34.         if not target:FindFirstChild("BodyPosition") then
  35.            
  36.             local bp = Instance.new("BodyPosition", target)
  37.             bp.D = 100
  38.             bp.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  39.         end
  40.        
  41.         if not target:FindFirstChild("BodyGyro") then
  42.            
  43.             local bg = Instance.new("BodyGyro", target)
  44.             bg.D = 100
  45.             bg.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
  46.         end
  47.        
  48.        
  49.         target.Anchored = false
  50.        
  51.         target:SetNetworkOwner(plr)
  52.     end
  53. end)
Add Comment
Please, Sign In to add comment