Advertisement
rahuliscool

canball script

Nov 27th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. if script == nil then return end
  4.  
  5.  
  6.  
  7.  
  8. Player = script:FindFirstChild("Player") ~= nil and script.Player.Value or game:GetService("Players"):FindFirstChild("thesuperfireguy9000")
  9. Name = "Can Bomb"
  10. selected = false
  11. Button1Down = false
  12. thrown = false
  13.  
  14.  
  15. function makeParts(format)
  16.     local grenade = Instance.new("Model")
  17.     grenade.Name = Name
  18.     grenade.Parent = Player.Character
  19.     local pm = Instance.new("Part")
  20.     pm.Name = "Handle"
  21.     pm.formFactor = "Symmetric"
  22.     pm.Size = Vector3.new(1, 1, 1)
  23.     pm.BrickColor = BrickColor.new("Black")
  24.     pm.CanCollide = false
  25.     pm.Locked = true
  26.     pm.TopSurface = 0
  27.     pm.BottomSurface = 0
  28.     pm.Parent = grenade
  29.     local m = Instance.new("SpecialMesh")
  30.     m.MeshType = "FileMesh"
  31.     m.Scale = Vector3.new(1, 1, 1)
  32.     m.MeshId = "http://www.roblox.com/asset/?id=10470609"
  33.     m.TextureId = "http://www.roblox.com/asset/?id=45934917"
  34.     m.Parent = pm
  35.     local w = Instance.new("Weld")
  36.     w.Part0 = pm
  37.     if format == "hand" then
  38.         w.Part1 = Player.Character:FindFirstChild("Right Arm")
  39.         w.C0 = CFrame.new(-1.2, 0, 0) * CFrame.fromEulerAnglesXYZ(math.rad(90), 0, math.rad(90))
  40.         w.C1 = CFrame.new()
  41.     elseif format == "holster" then
  42.         w.Part1 = Player.Character:FindFirstChild("Torso")
  43.         w.C0 = CFrame.new(0.6, -0.4, 0.6)
  44.         w.C1 = CFrame.new()
  45.         grenade.Name = Name.. " (Holstered)"
  46.     end
  47.     w.Parent = pm
  48.     local s = Instance.new("Sound")
  49.     s.Name = "Explode"
  50.     s.SoundId = "rbxasset://sounds\\collide.wav"
  51.     s.Volume = 1
  52.     s.Pitch = 1
  53.     s.Looped = false
  54.     s.Parent = pm
  55.     local s = Instance.new("Sound")
  56.     s.Name = "Pin"
  57.     s.SoundId = "http://www.roblox.com/Asset/?id=31760113"
  58.     s.Volume = 1
  59.     s.Pitch = 1
  60.     s.Looped = true
  61.     s.Parent = pm
  62.     local s = Instance.new("Sound")
  63.     s.Name = "Light"
  64.     s.SoundId = "http://www.roblox.com/Asset/?id=19095020"
  65.     s.Volume = 1
  66.     s.Pitch = 1
  67.     s.Looped = false
  68.     s.Parent = pm
  69.     local p = Instance.new("Part")
  70.     p.Name = "Rag"
  71.     p.formFactor = "Symmetric"
  72.     p.Size = Vector3.new(1, 1, 1)
  73.     p.BrickColor = BrickColor.new("White")
  74.     p.CanCollide = false
  75.     p.Transparency = 1
  76.     p.Locked = true
  77.     p.TopSurface = 0
  78.     p.BottomSurface = 0
  79.     p.Parent = grenade
  80.     local f = Instance.new("Fire")
  81.     f.Enabled = false
  82.     f.Name = "Fire"
  83.     f.Color = Color3.new(1, 0.5, 0)
  84.     f.SecondaryColor = Color3.new(1, 0.75, 0.5)
  85.     f.Heat = 25
  86.     f.Size = 2
  87.     f.Parent = p
  88.     local m = Instance.new("CylinderMesh")
  89.     m.Scale = Vector3.new(0.15, 0.4, 0.15)
  90.     m.Parent = p
  91.     local w = Instance.new("Weld")
  92.     w.Part0 = p
  93.     w.Part1 = pm
  94.     w.C0 = CFrame.new(0, -0.6, 0)
  95.     w.C1 = CFrame.new()
  96.     w.Parent = p
  97. end
  98.  
  99.  
  100. function removeParts(format)
  101.     if format == "hand" then
  102.         if Player.Character:FindFirstChild(Name) ~= nil then
  103.             Player.Character[Name]:Remove()
  104.         end
  105.     elseif format == "holster" then
  106.         if Player.Character:FindFirstChild(Name.. " (Holstered)") ~= nil then
  107.             Player.Character[Name.. " (Holstered)"]:Remove()
  108.         end
  109.     end
  110. end
  111.  
  112.  
  113. function SetAngle(Joint, Angle, Character)
  114.     if Character == nil then return false end
  115.     local Joints = {
  116.         Character.Torso:FindFirstChild("Right Shoulder 2"),
  117.         Character.Torso:FindFirstChild("Left Shoulder 2"),
  118.         Character.Torso:FindFirstChild("Right Hip 2"),
  119.         Character.Torso:FindFirstChild("Left Hip 2")
  120.     }
  121.     if Joints[Joint] == nil then return false end
  122.     if Joint == 1 or Joint == 3 then
  123.         Joints[Joint].DesiredAngle = Angle
  124.     end
  125.     if Joint == 2 or Joint == 4 then
  126.         Joints[Joint].DesiredAngle = -Angle
  127.     end
  128. end
  129.  
  130.  
  131. function ForceAngle(Joint, Angle, Character)
  132.     if Character == nil then return false end
  133.     local Joints = {
  134.         Character.Torso:FindFirstChild("Right Shoulder 2"),
  135.         Character.Torso:FindFirstChild("Left Shoulder 2"),
  136.         Character.Torso:FindFirstChild("Right Hip 2"),
  137.         Character.Torso:FindFirstChild("Left Hip 2")
  138.     }
  139.     if Joints[Joint] == nil then return false end
  140.     if Joint == 1 or Joint == 3 then
  141.         Joints[Joint].DesiredAngle = Angle
  142.         Joints[Joint].CurrentAngle = Angle
  143.     end
  144.     if Joint == 2 or Joint == 4 then
  145.         Joints[Joint].DesiredAngle = -Angle
  146.         Joints[Joint].CurrentAngle = -Angle
  147.     end
  148. end
  149.  
  150.  
  151. function SetSpeed(Joint, Speed, Character)
  152.     if Character == nil then return false end
  153.     local Joints = {
  154.         Character.Torso:FindFirstChild("Right Shoulder 2"),
  155.         Character.Torso:FindFirstChild("Left Shoulder 2"),
  156.         Character.Torso:FindFirstChild("Right Hip 2"),
  157.         Character.Torso:FindFirstChild("Left Hip 2")
  158.     }
  159.     if Joints[Joint] == nil then return false end
  160.     Joints[Joint].MaxVelocity = Speed
  161. end
  162.  
  163.  
  164. function DisableLimb(Limb, Character)
  165.     if Character == nil then return false end
  166.     if Character:FindFirstChild("Torso") == nil then return false end
  167.     local Joints = {
  168.         Character.Torso:FindFirstChild("Right Shoulder"),
  169.         Character.Torso:FindFirstChild("Left Shoulder"),
  170.         Character.Torso:FindFirstChild("Right Hip"),
  171.         Character.Torso:FindFirstChild("Left Hip")
  172.     }
  173.     local Limbs = {
  174.         Character:FindFirstChild("Right Arm"),
  175.         Character:FindFirstChild("Left Arm"),
  176.         Character:FindFirstChild("Right Leg"),
  177.         Character:FindFirstChild("Left Leg")
  178.     }
  179.     if Joints[Limb] == nil then return false end
  180.     if Limbs[Limb] == nil then return false end
  181.     local Joint = Instance.new("Motor")
  182.     Joint.Parent = Character.Torso
  183.     Joint.Part0 = Character.Torso
  184.     Joint.Part1 = Limbs[Limb]
  185.     if Limb == 1 then
  186.         Joint.C0 = CFrame.new(1.5, 0.5, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0)
  187.         Joint.C1 = CFrame.new(0, 0.5, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0)
  188.         Joint.Name = "Right Shoulder 2"
  189.     elseif Limb == 2 then
  190.         Joint.C0 = CFrame.new(-1.5, 0.5, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(-90), 0)
  191.         Joint.C1 = CFrame.new(0, 0.5, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(-90), 0)
  192.         Joint.Name = "Left Shoulder 2"
  193.     elseif Limb == 3 then
  194.         Joint.C0 = CFrame.new(0.5, -1, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0)
  195.         Joint.C1 = CFrame.new(0, 1, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0)
  196.         Joint.Name = "Right Hip 2"
  197.     elseif Limb == 4 then
  198.         Joint.C0 = CFrame.new(-0.5, -1, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(-90), 0)
  199.         Joint.C1 = CFrame.new(0, 1, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(-90), 0)
  200.         Joint.Name = "Left Hip 2"
  201.     end
  202.     Joint.MaxVelocity = Joints[Limb].MaxVelocity
  203.     Joint.CurrentAngle = Joints[Limb].CurrentAngle
  204.     Joint.DesiredAngle = Joints[Limb].DesiredAngle
  205.     Joints[Limb]:Remove()
  206. end
  207.  
  208.  
  209. function ResetLimbCFrame(Limb, Character)
  210.     if Character == nil then return false end
  211.     if Character.Parent == nil then return false end
  212.     if Character:FindFirstChild("Torso") == nil then return false end
  213.     local Joints = {
  214.         Character.Torso:FindFirstChild("Right Shoulder 2"),
  215.         Character.Torso:FindFirstChild("Left Shoulder 2"),
  216.         Character.Torso:FindFirstChild("Right Hip 2"),
  217.         Character.Torso:FindFirstChild("Left Hip 2")
  218.     }
  219.     local Limbs = {
  220.         Character:FindFirstChild("Right Arm"),
  221.         Character:FindFirstChild("Left Arm"),
  222.         Character:FindFirstChild("Right Leg"),
  223.         Character:FindFirstChild("Left Leg")
  224.     }
  225.     if Joints[Limb] == nil then return false end
  226.     if Limbs[Limb] == nil then return false end
  227.     if Limb == 1 then
  228.         Joints[Limb].C0 = CFrame.new(1.5, 0.5, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0)
  229.         Joints[Limb].C1 = CFrame.new(0, 0.5, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0)
  230.     elseif Limb == 2 then
  231.         Joints[Limb].C0 = CFrame.new(-1.5, 0.5, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(-90), 0)
  232.         Joints[Limb].C1 = CFrame.new(0, 0.5, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(-90), 0)
  233.     elseif Limb == 3 then
  234.         Joints[Limb].C0 = CFrame.new(0.5, -1, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0)
  235.         Joints[Limb].C1 = CFrame.new(0, 1, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0)
  236.     elseif Limb == 4 then
  237.         Joints[Limb].C0 = CFrame.new(-0.5, -1, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(-90), 0)
  238.         Joints[Limb].C1 = CFrame.new(0, 1, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(-90), 0)
  239.     end
  240. end
  241.  
  242.  
  243. function EnableLimb(Limb, Character)
  244.     if Character == nil then return false end
  245.     if Character:FindFirstChild("Torso") == nil then return false end
  246.     local Joints = {
  247.         Character.Torso:FindFirstChild("Right Shoulder 2"),
  248.         Character.Torso:FindFirstChild("Left Shoulder 2"),
  249.         Character.Torso:FindFirstChild("Right Hip 2"),
  250.         Character.Torso:FindFirstChild("Left Hip 2")
  251.     }
  252.     local Limbs = {
  253.         Character:FindFirstChild("Right Arm"),
  254.         Character:FindFirstChild("Left Arm"),
  255.         Character:FindFirstChild("Right Leg"),
  256.         Character:FindFirstChild("Left Leg")
  257.     }
  258.     if Joints[Limb] == nil then return false end
  259.     if Limbs[Limb] == nil then return false end
  260.     if Limb == 1 then
  261.         Joints[Limb].Name = "Right Shoulder"
  262.     elseif Limb == 2 then
  263.         Joints[Limb].Name = "Left Shoulder"
  264.     elseif Limb == 3 then
  265.         Joints[Limb].Name = "Right Hip"
  266.     elseif Limb == 4 then
  267.         Joints[Limb].Name = "Left Hip"
  268.     end
  269.     Animate = Character:FindFirstChild("Animate")
  270.     if Animate == nil then return false end
  271.     Animate = Animate:Clone()
  272.     Character.Animate:Remove()
  273.     Animate.Parent = Character
  274. end
  275.  
  276.  
  277. function Weld(x, y)
  278.     local weld = Instance.new("Weld")
  279.     weld.Part0 = x
  280.     weld.Part1 = y
  281.     CJ = CFrame.new(x.Position)
  282.     C0 = x.CFrame:inverse() * CJ
  283.     C1 = y.CFrame:inverse() * CJ
  284.     weld.C0 = C0
  285.     weld.C1 = C1
  286.     weld.Parent = x
  287. end
  288.  
  289.  
  290. function tagHumanoid(humanoid)
  291.     local tag = Instance.new("ObjectValue")
  292.     tag.Name = "creator"
  293.     tag.Value = Player
  294.     tag.Parent = humanoid
  295.     local tag = Instance.new("StringValue")
  296.     tag.Name = "creatorType1"
  297.     tag.Value = Name
  298.     tag.Parent = humanoid
  299.     local tag = Instance.new("StringValue")
  300.     tag.Name = "creatorType2"
  301.     tag.Value = "blown up"
  302.     tag.Parent = humanoid
  303. end
  304.  
  305.  
  306. function untagHumanoid(humanoid)
  307.     if humanoid ~= nil then
  308.         local tag = humanoid:FindFirstChild("creator")
  309.         if tag ~= nil then
  310.             tag:Remove()
  311.         end
  312.         local tag = humanoid:FindFirstChild("creatorType1")
  313.         if tag ~= nil then
  314.             tag:Remove()
  315.         end
  316.         local tag = humanoid:FindFirstChild("creatorType2")
  317.         if tag ~= nil then
  318.             tag:Remove()
  319.         end
  320.     end
  321. end
  322.  
  323.  
  324. function fire(v)
  325.     if Player.Character:FindFirstChild(Name) == nil then makeParts("hand") end
  326.     if Player.Character[Name]:FindFirstChild("Handle") == nil then return end
  327.     if Player.Character[Name].Handle:FindFirstChild("Weld") ~= nil then Player.Character[Name].Handle.Weld:Remove() end
  328.     local bodyVelocity = Instance.new("BodyVelocity")
  329.     bodyVelocity.maxForce = Vector3.new(math.huge, math.huge, math.huge)
  330.     bodyVelocity.velocity = v * 75
  331.     bodyVelocity.Parent = Player.Character[Name].Handle
  332.     wait(0.1)
  333.     bodyVelocity:Remove()
  334. end
  335.  
  336.  
  337. function onButton1Down(mouse)
  338.     if selected == false then return end
  339.     if Player.Character:FindFirstChild(Name) ~= nil and Button1Down ~= true and thrown ~= true then
  340.         if Player.Character[Name]:FindFirstChild("Handle") == nil then return end
  341.         Button1Down = true
  342.         mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
  343.         Player.Character[Name].Handle.Pin:Play()
  344.         Player.Character[Name].Handle.Light:Play()
  345.         Player.Character[Name].Rag.Fire.Enabled = true
  346.         Player.Character[Name].Handle.CanCollide = true
  347.         Player.Character[Name].Rag.CanCollide = true  
  348.         coroutine.resume(coroutine.create(function()
  349.             wait(math.random(3, 6))
  350.             if Player.Character:FindFirstChild(Name) ~= nil then
  351.                 if Player.Character[Name]:FindFirstChild("Handle") ~= nil then
  352.                     local e = Instance.new("Explosion")
  353.                     e.BlastPressure = 20
  354.                     e.BlastRadius = 10
  355.                     e.Position = Player.Character[Name].Handle.Position
  356.                     e.Parent = game:GetService("Workspace")
  357.                     e.Hit:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then tagHumanoid(hit.Parent.Humanoid) delay(1, function() untagHumanoid(hit.Parent.Humanoid) end) end end)
  358.                     Player.Character[Name].Handle.Explode:Play()
  359.                     Player.Character[Name].Handle.Transparency = 1
  360.                     Player.Character[Name].Handle.CanCollide = false
  361.                     Player.Character[Name].Handle.Pin:Stop()
  362.                 end
  363.             end
  364.             wait()
  365.             if Player.Character:FindFirstChild("WeaponActivated") ~= nil then
  366.                 Player.Character.WeaponActivated:Remove()
  367.             end
  368.             thrown = false
  369.             Button1Down = false
  370.             selected = true
  371.             onDeselected(mouse)
  372.             removeParts("holster")
  373.             script.Parent:Remove()
  374.         end))
  375.     end
  376. end
  377.  
  378.  
  379. function onButton1Up(mouse)
  380.     if selected == false then return end
  381.     if Button1Down == true and thrown ~= true then
  382.         thrown = true
  383.         mouse.Icon = "rbxasset://textures\\GunCursor.png"
  384.         SetSpeed(1, 2, Player.Character)
  385.         SetAngle(1, 0, Player.Character)
  386.         EnableLimb(1, Player.Character)
  387.         fire((mouse.Hit.p - Player.Character[Name].Handle.Position).unit)
  388.     end
  389.     Button1Down = false
  390. end
  391.  
  392.  
  393. function onKeyDown(key, mouse)
  394.     if selected == false then return end
  395.     key = key:lower()
  396.     if key == "q" and Button1Down == false and thrown ~= true then
  397.         if mouse.Target == nil then return end
  398.         if game:GetService("Players"):GetPlayerFromCharacter(mouse.Target.Parent) ~= nil then
  399.             onDeselected(mouse)
  400.             removeParts("holster")
  401.             script.Parent.Parent = game:GetService("Players"):GetPlayerFromCharacter(mouse.Target.Parent).Backpack
  402.         end
  403.     end
  404. end
  405.  
  406.  
  407. function onSelected(mouse)
  408.     if selected == true then return end
  409.     selected = true
  410.     mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
  411.     while Player.Character:FindFirstChild("WeaponActivated") ~= nil or thrown == true do
  412.         if Player.Character.WeaponActivated.Value == nil then break end
  413.         if Player.Character.WeaponActivated.Value.Parent == nil then break end
  414.         wait()
  415.     end
  416.     mouse.Icon = "rbxasset://textures\\GunCursor.png"
  417.     removeParts("holster")
  418.     makeParts("hand")
  419.     local weapon = Instance.new("ObjectValue")
  420.     weapon.Name = "WeaponActivated"
  421.     weapon.Value = script.Parent
  422.     weapon.Parent = Player.Character
  423.     DisableLimb(1, Player.Character)
  424.     SetAngle(1, math.rad(200), Player.Character)
  425.     mouse.Button1Down:connect(function() onButton1Down(mouse) end)
  426.     mouse.Button1Up:connect(function() onButton1Up(mouse) end)
  427.     mouse.KeyDown:connect(function(key) onKeyDown(key, mouse) end)
  428. end
  429.  
  430.  
  431. function onDeselected(mouse)
  432.     if selected == false then return end
  433.     selected = false
  434.     while Button1Down == true or thrown == true do
  435.         wait()
  436.     end
  437.     if Player.Character:FindFirstChild("WeaponActivated") ~= nil then
  438.         if Player.Character.WeaponActivated.Value == script.Parent then
  439.             Player.Character.WeaponActivated:Remove()
  440.         end
  441.     end
  442.     while Player.Character:FindFirstChild("WeaponActivated") ~= nil do
  443.         if Player.Character.WeaponActivated.Value == nil then break end
  444.         if pcall(function() if Player.Character.WeaponActivated.Value.Parent == nil then return true end end) then break end
  445.         wait()
  446.     end
  447.     removeParts("hand")
  448.     makeParts("holster")
  449.     SetAngle(1, 0, Player.Character)
  450.     EnableLimb(1, Player.Character)
  451. end
  452.  
  453.  
  454. if script.Parent.className ~= "HopperBin" then
  455.     if Player == nil then print("Error: Player not found!") return end
  456.     Tool = Instance.new("HopperBin")
  457.     Tool.Name = Name
  458.     Tool.Parent = Player.Backpack
  459.     script.Name = "Main"
  460.     script.Parent = Tool
  461. elseif script.Parent.className == "HopperBin" then
  462.     while script.Parent.Parent.className ~= "Backpack" do
  463.         wait()
  464.     end
  465.     Player = script.Parent.Parent.Parent
  466.     makeParts("holster")
  467.     script.Parent.Selected:connect(onSelected)
  468.     script.Parent.Deselected:connect(onDeselected)
  469. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement