Advertisement
Guest User

Sticks Reload Script

a guest
Aug 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. --//Updated Script
  2. --//Variables
  3. local plr = game.Players.LocalPlayer
  4. local tool = script.Parent.Parent
  5. local hole = tool.Hole
  6. local handle = tool.Handle
  7. local debounce = true
  8. local config = tool.Config
  9. local range = config.Range
  10. local dmg = config.Damage
  11. local coolDown = config.CoolDown
  12. local clips = config.Clips
  13. local ammo = config.Ammo
  14. local maxAmmo = config.MaxAmmo
  15. local allowTracing = config.AllowTracing
  16. local reloadTime = config.ReloadTime
  17. local isReloading = false
  18.  
  19. --//Events
  20. tool.Equipped:connect(function(mouse)
  21. tool.Activated:connect(function()
  22. if not isReloading then
  23. if ammo.Value > 0 then
  24. if debounce then
  25. --//Doesn't allow spamming
  26. debounce = false
  27. --//Ray Get, Set
  28. local ray = Ray.new(hole.CFrame.p, (mouse.Hit.p - hole.CFrame.p) * range.Value)
  29. local hit, position = workspace:FindPartOnRay(ray, plr.Character, false, true)
  30.  
  31. --//Bullet Tracing
  32. if allowTracing.Value == true then
  33. --//Make part
  34. local trace = Instance.new("Part", workspace)
  35. trace.Material = Enum.Material.Neon
  36. trace.BrickColor = BrickColor.new("Black")
  37. trace.CanCollide = false
  38. trace.Anchored = true
  39. trace.Transparency = 0.5
  40.  
  41. --//Show Direction
  42. local distance = (hole.CFrame.p - position).magnitude
  43. trace.Size = Vector3.new(0.2, 0.2, distance)
  44. trace.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new(0, 0, -distance/2)
  45.  
  46. --//Remove debris
  47. game:GetService("Debris"):AddItem(trace, 0.1)
  48. end
  49.  
  50. --//Hit Detection
  51. if hit then
  52. local humanoid = hit.Parent:FindFirstChild("Humanoid")
  53. if humanoid then
  54. if hit.Name == "Head" then
  55. --//Double damage on headshots
  56. humanoid:TakeDamage(dmg.Value*2)
  57. else
  58. --//Normal Damage on body shots
  59. humanoid:TakeDamage(dmg.Value)
  60. end
  61. end
  62. end
  63. ammo.Value = ammo.Value - 1
  64. wait(coolDown.Value)
  65. debounce = true
  66. end
  67. else
  68. --//Out of ammo
  69. end
  70. end
  71. end)
  72.  
  73. --//Reload Event
  74. mouse.KeyDown:connect(function(key)
  75. key:lower()
  76. if key == "r" then
  77. if not isReloading then
  78. if clips.Value > 0 then
  79. isReloading = true
  80. ammo.Value = maxAmmo.Value
  81. clips.Value = clips.Value - 1
  82. wait(reloadTime.Value)
  83. isReloading = false
  84. end
  85. end
  86. end
  87. end)
  88. end)
  89.  
  90. --LocalScript In the scripts folder
  91. repeat wait() until game.Players.LocalPlayer.PlayerGui.AmmoGui.Display
  92.  
  93. --//Variables
  94. local plr = game.Players.LocalPlayer
  95. local tool = script.Parent.Parent
  96. local config = tool.Config
  97. local ammo = config.Ammo
  98. local clips = config.Clips
  99. local display = plr.PlayerGui.AmmoGui.Display
  100.  
  101. --//Function(s)
  102. local function Update()
  103. display.Text = ammo.Value .. "/" .. clips.Value
  104. end
  105.  
  106. --//Events
  107. tool.Activated:connect(Update)
  108. ammo.Changed:connect(Update)
  109. clips.Changed:connect(Update)
  110.  
  111. tool.Equipped:connect(function()
  112. display.Visible = true
  113. Update()
  114. end)
  115.  
  116. tool.Dequipped:connect(function()
  117. display.Visible = false
  118. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement