Advertisement
Guest User

roblox grab script

a guest
Jan 17th, 2018
3,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. local RStorage = game:GetService('ReplicatedStorage');
  2. local RService = game:GetService('RunService');
  3. local ObjectFunction = RStorage:WaitForChild('ObjectFunction');
  4. local UnequippedString = 'None';
  5. local WeldModel = require(script:WaitForChild('WeldModel'));
  6.  
  7. local R6 = Enum.HumanoidRigType.R6;
  8. local R15 = Enum.HumanoidRigType.R15;
  9.  
  10. local function GetObj(player)
  11. for i,v in pairs(workspace:GetDescendants()) do
  12. if (v:FindFirstChild('EquippedBy')) and (v.EquippedBy.Value == player.Name) then
  13. return v;
  14. end end
  15. return nil;
  16. end
  17.  
  18. ObjectFunction.OnServerInvoke = function(player,Obj,Equipped,Hovering,Weld)
  19. if Weld ~= nil then
  20. Weld[1].C0 = Weld[2]
  21. return end;
  22. local Character = player.Character;
  23. local RigType = Character:WaitForChild('Humanoid').RigType;
  24. local Hand;
  25. if RigType == R6 then
  26. Hand = Character:WaitForChild('Right Arm');
  27. elseif RigType == R15 then
  28. Hand = Character:WaitForChild('RightHand');
  29. end
  30. if Equipped then
  31. local OldObj = GetObj(player)
  32. if OldObj:IsA('Model') then
  33. for i,v in pairs(OldObj:GetDescendants()) do
  34. if v:IsA('BasePart') then v.CanCollide = true;
  35. end end
  36. elseif OldObj:IsA('BasePart') then
  37. OldObj:FindFirstChildOfClass('Weld'):remove();
  38. OldObj.CanCollide = true;
  39. end
  40. OldObj.EquippedBy.Value = UnequippedString;
  41. end
  42. if Hovering then
  43. if (Obj.Parent:IsA('Model')) and (Obj.Parent:FindFirstChild('EquippedBy')) then
  44. local Model = Obj.Parent;
  45. local PrimaryPart = Model.PrimaryPart;
  46. if (not Model:FindFirstChild('EquippedBy')) then return{false,nil} end
  47. WeldModel.PerfectionWeld(Model);
  48. for i,v in pairs(Model:GetDescendants()) do if v:IsA('BasePart') then v.CanCollide = false end end;
  49. Model.EquippedBy.Value = player.Name;
  50. spawn(function()
  51. while (Model.EquippedBy.Value == player.Name) do
  52. RService.Heartbeat:wait();
  53. local lv = -Hand.CFrame.upVector;
  54. local size = PrimaryPart.Size.Y/2;
  55. Model:SetPrimaryPartCFrame(Hand.CFrame+Vector3.new(lv.X*size,lv.Y*size,lv.Z*size))
  56. end end)
  57. elseif Obj:IsA('BasePart') then
  58. if not Obj:FindFirstChild('EquippedBy') then return{Equipped} end;
  59. Obj.Anchored = false;
  60. local W = Instance.new('Weld',Obj);
  61. Obj.CanCollide = false;
  62. W.Part0 = Hand; W.Part1 = Obj;
  63. if RigType == R6 then
  64. W.C0 = CFrame.new(0,(-Obj.Size.Y/2)-.95,0)
  65. elseif RigType == R15 then
  66. W.C0 = CFrame.new(0,(-Obj.Size.Y/2)+.05,0)
  67. end
  68. Obj.EquippedBy.Value = player.Name;
  69. end
  70. end
  71. local EquipCheck = GetObj(player)
  72. if EquipCheck ~= nil then return{true,EquipCheck} else return{false,nil} end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement