Advertisement
KHSora455

Laser Gun

Jul 17th, 2015
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. function snapToTorso(pos)
  2. local list = game.Workspace:children()
  3. local torso = nil
  4. local dist = 100
  5. local temp = nil
  6. local human = nil
  7. local temp2 = nil
  8. for x = 1, #list do
  9. temp2 = list[x]
  10. if (temp2.className == "Model") and (temp2 ~= script.Parent) then
  11. temp = temp2:findFirstChild("Torso")
  12. human = temp2:findFirstChild("Humanoid")
  13. if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
  14. if (temp.Position - pos).magnitude < dist then
  15. torso = temp
  16. dist = (temp.Position - pos).magnitude
  17. annihilate()
  18. end
  19. end
  20. end
  21. end
  22. return torso
  23. end
  24.  
  25. function annihilate(gun,targ)
  26. pcall(function() p:remove() end)
  27. p = Instance.new("Part")
  28. p.BrickColor = BrickColor.new(21)
  29. p.Anchored = true
  30. p.CanCollide = false
  31. p.formFactor = "Plate"
  32. p.Size = Vector3.new(1,0.4,1)
  33. p.TopSurface = "Smooth"
  34. p.BottomSurface = "Smooth"
  35. local sm = Instance.new("SpecialMesh")
  36. sm.MeshType = "Sphere"
  37. sm.Parent = p
  38. local mag = (gun.Position - targ).magnitude
  39. local aim = CFrame.new(gun.Position,targ)
  40. p.CFrame = aim + (aim.lookVector * (mag / 2))
  41. sm.Scale = Vector3.new(0.2,0.2,mag )
  42. p.Parent = workspace
  43. coroutine.resume(coroutine.create(function()
  44. wait(0.3)
  45. pcall(function() p:remove() end)
  46. end))
  47. end
  48. laser(script.Parent.Shooter,torso)
  49. local ex = Instance.new("Explosion")
  50. ex.Position = torso
  51. ex.BlastRadius = 3
  52. ex.Parent = workspace
  53. end)
  54. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement