Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. local tool = script.Parent
  2. local player = game:GetService("Players").LocalPlayer
  3. local character = workspace:WaitForChild(player.Name)
  4. local humanoid = character:WaitForChild("Humanoid")
  5. local shootingOn = false
  6. local mouse = player:GetMouse()
  7. local Ammo = script.Parent.AmmoScript.Ammo
  8.  
  9. local FireTime = 0.1 -- counts in secs
  10.  
  11. local canFire = true
  12. local equipped = false
  13. local shootingOn = false
  14.  
  15. function Shoot()
  16. local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
  17. local part, position = workspace:FindPartOnRay(ray, character, false, true)
  18.  
  19. local beam = Instance.new("Part", workspace)
  20. beam.BrickColor = BrickColor.new("Bright yellow")
  21. beam.FormFactor = "Custom"
  22. beam.Material = "Neon"
  23. beam.Transparency = 0.25
  24. beam.Anchored = true
  25. beam.Locked = true
  26. beam.CanCollide = false
  27.  
  28. local distance = (tool.Handle.CFrame.p - position).magnitude
  29. beam.Size = Vector3.new(0.3, 0.3, distance)
  30. beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
  31.  
  32. game:GetService("Debris"):AddItem(beam, 0.1)
  33.  
  34. if part then
  35. local zombiePlayer = part.Parent:FindFirstChild("Zombie")
  36. if not zombiePlayer then
  37. zombiePlayer = part.Parent.Parent:FindFirstChild("Zombie")
  38. end
  39. if zombiePlayer then
  40. zombiePlayer:TakeDamage(15)
  41. end
  42. end
  43. end
  44.  
  45.  
  46. tool.Equipped:connect(function()
  47. equipped = true
  48. mouse.Button1Down:connect(function()
  49. shootingOn = true
  50. if equipped and canFire and Ammo.Value == 0 and humanoid.Health ~= 0 then
  51. canFire = false
  52. while shootingOn do
  53. Ammo.Value = Ammo.Value - 1
  54. script.Parent.Handle.Fire:Play()
  55. Shoot()
  56. wait(FireTime)
  57. canFire = true
  58. if not shootingOn or Ammo.Value == 0 or not equipped then
  59. break
  60. end
  61. end
  62. end
  63. end)
  64. mouse.Button1Up:connect(function()
  65. shootingOn = false
  66. end)
  67. end)
  68.  
  69. tool.Unequipped:connect(function()
  70. equipped = false
  71. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement