Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. --//Variables
  2. local plr = game.Players.LocalPlayer
  3. local tool = script.Parent.Parent
  4. local hole = tool:WaitForChild("Hole")
  5. local handle = tool:WaitForChild("Handle")
  6. local debounce = true
  7. local config = tool:WaitForChild("Config")
  8. local range = config:WaitForChild("Range")
  9. local dmg = config:WaitForChild("Damage")
  10. local coolDown = config:WaitForChild("CoolDown")
  11. local clips = config:WaitForChild("Clips")
  12. local ammo = config:WaitForChild("Ammo")
  13. local maxAmmo = config:WaitForChild("MaxAmmo")
  14. local allowTracing = config:WaitForChild("AllowTracing")
  15. local reloadTime = config:WaitForChild("ReloadTime")
  16. local NumOfBullets = config:WaitForChild("NumOfBullets")
  17. local radius = config:WaitForChild("Radius")
  18. local Rays = {}
  19. local isReloading = false
  20. --//Sounds
  21. local reloadSound = handle:WaitForChild("ReloadSound")
  22. local fireSound = handle:WaitForChild("FireSound")
  23. local equipSound = handle:WaitForChild("EquipSound")
  24. local emptySound = handle:WaitForChild("EmptySound")
  25. --//Animations
  26. repeat wait() until plr.Character.Humanoid
  27. local AnimFolder = script.Parent.Parent:WaitForChild("Animations")
  28. local ReloadTrack = plr.Character.Humanoid:LoadAnimation(AnimFolder:WaitForChild("PistolReload"))
  29. local AimTrack = plr.Character.Humanoid:LoadAnimation(AnimFolder:WaitForChild("PistolAim"))
  30. local HoldTrack = plr.Character.Humanoid:LoadAnimation(AnimFolder:WaitForChild("PistolHold"))
  31. AimTrack.Looped = true
  32. HoldTrack.Looped = true
  33.  
  34. --//Events
  35. tool.Equipped:connect(function(mouse)
  36. equipSound:Play()
  37. HoldTrack:Play()
  38.  
  39. mouse.KeyDown:connect(function(Key)
  40. if Key:lower() == "q" then
  41. workspace.CurrentCamera.FieldOfView = 60
  42. AimTrack:Play()
  43. end
  44. end)
  45.  
  46. mouse.KeyUp:connect(function(Key)
  47. if Key:lower() == "q" then
  48. workspace.CurrentCamera.FieldOfView = 70
  49. AimTrack:Stop()
  50. end
  51. end)
  52.  
  53. mouse.Button1Down:connect(function()
  54. if debounce then
  55. Shoot()
  56. end
  57. end)
  58.  
  59. --//Reload Event
  60. mouse.KeyDown:connect(function(key)
  61. if key:lower() == "r" then
  62. if not isReloading then
  63. if clips.Value > 0 then
  64. ReloadTrack:Play()
  65. reloadSound:Play()
  66. isReloading = true
  67. ammo.Value = maxAmmo.Value
  68. clips.Value = clips.Value - 1
  69. debounce = false
  70. wait(reloadTime.Value)
  71. isReloading = false
  72. debounce = true
  73. end
  74. end
  75. end
  76. end)
  77.  
  78. function Shoot()
  79. if not isReloading then
  80. if ammo.Value > 0 then
  81. if debounce then
  82. --//Play sound
  83. fireSound:Play()
  84. --//Doesn't allow spamming
  85. debounce = false
  86. for i=1, NumOfBullets.Value do
  87. --//Ray Get, Set
  88. local ray = Ray.new(hole.CFrame.p, (mouse.Hit.p - hole.CFrame.p + Vector3.new(math.random(-radius.Value, radius.Value), math.random(-radius.Value, radius.Value), 0)) * range.Value)
  89. table.insert(Rays, ray)
  90. end
  91.  
  92. --//Bullet Tracing
  93. if allowTracing.Value == true then
  94. for i, RayPart in pairs(Rays) do
  95. --//Make part
  96. local trace = Instance.new("Part", workspace)
  97. trace.Material = Enum.Material.Neon
  98. trace.BrickColor = BrickColor.new("New Yeller")
  99. trace.CanCollide = false
  100. trace.Anchored = true
  101. trace.Transparency = 0.5
  102.  
  103. --//Position Getting\\--
  104. local hit, position = workspace:FindPartOnRay(RayPart, plr.Character, false, true)
  105.  
  106. --//Show Direction
  107. local distance = (hole.CFrame.p - position).magnitude
  108. trace.Size = Vector3.new(0.2, 0.2, distance)
  109. trace.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new(0, 0, -distance/2)
  110.  
  111. --//Remove Tracings\\--
  112. game:GetService("Debris"):AddItem(trace, 0.1)
  113. end
  114. end
  115.  
  116. for i, RayPart in pairs(Rays) do
  117. --//Hit Getting\\--
  118. local hit = workspace:FindPartOnRay(RayPart, plr.Character, false, true)
  119.  
  120. --//Hit Detection
  121. if hit then
  122. local humanoid = hit.Parent:FindFirstChild("Humanoid")
  123. if humanoid then
  124. if hit.Name == "Head" then
  125. --//Double damage on headshots
  126. humanoid:TakeDamage(dmg.Value*2)
  127. else
  128. --//Normal Damage on body shots
  129. humanoid:TakeDamage(dmg.Value)
  130. end
  131. end
  132. end
  133. end
  134. wait(coolDown.Value)
  135. ammo.Value = ammo.Value - 1
  136. for i=NumOfBullets.Value, 1, -1 do
  137. table.remove(Rays, i)
  138. end
  139. debounce = true
  140. end
  141. else
  142. --//Out of ammo
  143. emptySound:Play()
  144. debounce = false
  145. end
  146. end
  147. end
  148. end)
  149.  
  150. tool.Unequipped:connect(function()
  151. AimTrack:Stop()
  152. HoldTrack:Stop()
  153. ReloadTrack:Stop()
  154. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement