Advertisement
zack785

Untitled

Jan 31st, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local Player = game.Players.LocalPlayer
  2. repeat wait() until Player.Character
  3. local Character = Player.Character
  4. local Humanoid = Character:WaitForChild("Humanoid")
  5. local SMG = Character:WaitForChild("SMG")
  6. local Flash = SMG:WaitForChild("Flash")
  7.  
  8. local Mouse=Player:GetMouse()
  9. local Obj=nil
  10. local Prop=nil
  11. local IsAModel=nil
  12. local Grabbing=false
  13. local Primary=nil
  14.  
  15. Mouse.KeyDown:connect(function(key)
  16.     if key == "e" then
  17.         local success, output = pcall(function()
  18.             if not Grabbing then
  19.                 if Mouse.Target~=nil then
  20.                     local Target=Mouse.Target
  21.                     if Target:FindFirstChild("Prop") then
  22.                         Obj=Target
  23.                         Primary=Obj
  24.                     elseif Target.Parent:FindFirstChild("Prop") then
  25.                         Obj=Target.Parent
  26.                         if not Target:IsA("UnionOperation") then
  27.                             Primary=Obj.PrimaryPart
  28.                         else
  29.                             Primary=Target
  30.                         end
  31.                     end
  32.                     if Obj then
  33.                         if Obj.ClassName == "Model" then
  34.                             IsAModel = true
  35.                         else
  36.                             IsAModel = false
  37.                         end
  38.                         print("Is a model: "..tostring(IsAModel))
  39.                         Prop=Obj.Prop
  40.                         print(Primary.Name)
  41.                         local Distance=(Primary.Position-Flash.Position).magnitude
  42.                         if Distance <=15 then
  43.                             if not Prop.Value then
  44.                                 Grabbing = true
  45.                                 Prop.Value = true
  46.                                 if IsAModel then
  47.                                     for a,c in ipairs(Obj:children()) do
  48.                                         local bp = Instance.new("BodyPosition",c)
  49.                                         delay(0, function()
  50.                                             while Grabbing do
  51.                                                 bp.position = (Flash.CFrame*CFrame.new(0,Distance,0)).p
  52.                                                 wait()
  53.                                             end
  54.                                         end)
  55.                                     end
  56.                                 else
  57.                                     local bp = Instance.new("BodyPosition",Obj)
  58.                                     while Grabbing do
  59.                                         bp.position=(Flash.CFrame*CFrame.new(0,Distance,0)).p
  60.                                         wait()
  61.                                     end
  62.                                 end
  63.                             end
  64.                         end
  65.                     end
  66.                 end
  67.             else
  68.                 Grabbing=false
  69.                 Prop.Value=false
  70.                 if IsAModel then
  71.                     for a,c in ipairs(Obj:children()) do
  72.                         local bp = c:FindFirstChild("BodyPosition")
  73.                         if bp then
  74.                             bp:remove()
  75.                         end
  76.                     end
  77.                 else
  78.                     local bp = Obj:FindFirstChild("BodyPosition")
  79.                     if bp then
  80.                         bp:remove()
  81.                     end
  82.                 end
  83.                 Obj = nil
  84.                 Prop = nil
  85.                 IsAModel = nil
  86.             end
  87.         end)
  88.  
  89.         if not success then
  90.             pcall(function()
  91.                 error(output)
  92.             end)
  93.         end
  94.     end
  95. end)
  96.  
  97. Humanoid.Died:connect(function()
  98.     if Grabbing then
  99.         Grabbing=false
  100.         Prop.Value=false
  101.         if IsAModel then
  102.             for a,c in ipairs(Obj:children()) do
  103.                 local bp=c:FindFirstChild("BodyPosition")
  104.                 if bp then
  105.                     bp:remove()
  106.                 end
  107.             end
  108.         else
  109.             local bp=Obj:FindFirstChild("BodyPosition")
  110.             if bp then
  111.                 bp:remove()
  112.             end
  113.         end
  114.         Obj=nil
  115.         Prop=nil
  116.         IsAModel=nil
  117.     end
  118. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement