Advertisement
Guest User

Sticks gun script

a guest
Aug 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. --//Local Script Inside folder
  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.  
  17. --//Events
  18. tool.Equipped:connect(function(mouse)
  19. tool.Activated:connect(function()
  20. if debounce then
  21. --//Doesn't allow spamming
  22. debounce = false
  23. --//Ray Get, Set
  24. local ray = Ray.new(hole.CFrame.p, (mouse.Hit.p - hole.CFrame.p) * range.Value)
  25. local hit, position = workspace:FindPartOnRay(ray, plr.Character, false, true)
  26.  
  27. --//Bullet Tracing
  28. if allowTracing.Value == true then
  29. --//Make part
  30. local trace = Instance.new("Part", workspace)
  31. trace.Material = Enum.Material.Neon
  32. trace.BrickColor = BrickColor.new("Black")
  33. trace.CanCollide = false
  34. trace.Anchored = true
  35. trace.Transparency = 0.5
  36.  
  37. --//Show Direction
  38. local distance = (hole.CFrame.p - position).magnitude
  39. trace.Size = Vector3.new(0.2, 0.2, distance)
  40. trace.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new(0, 0, -distance/2)
  41.  
  42. --//Remove debris
  43. game:GetService("Debris"):AddItem(trace, 0.1)
  44. end
  45.  
  46. --//Hit Detection
  47. if hit then
  48. local humanoid = hit.Parent:FindFirstChild("Humanoid")
  49. if humanoid then
  50. if hit.Name == "Head" then
  51. --//Double damage on headshots
  52. humanoid:TakeDamage(dmg.Value*2)
  53. else
  54. --//Normal Damage on body shots
  55. humanoid:TakeDamage(dmg.Value)
  56. end
  57. end
  58. end
  59.  
  60. wait(coolDown.Value)
  61. debounce = true
  62. end
  63. end)
  64. end)
  65.  
  66. --//Weld script inside folder if gun parts all apart
  67. local tool = script.Parent.Parent
  68.  
  69. function Weld(x,y)
  70. local W = Instance.new("Weld")
  71. W.Part0 = x
  72. W.Part1 = y
  73. local CJ = CFrame.new(x.Position)
  74. local C0 = x.CFrame:inverse()*CJ
  75. local C1 = y.CFrame:inverse()*CJ
  76. W.C0 = C0
  77. W.C1 = C1
  78. W.Parent = x
  79. end
  80.  
  81. function Get(A)
  82. if A.className == "Part" then
  83. Weld(tool.Handle, A)
  84. A.Anchored = false
  85. else
  86. local C = A:GetChildren()
  87. for i=1, #C do
  88. Get(C[i])
  89. end
  90. end
  91. end
  92.  
  93. function Finale()
  94. Get(tool)
  95. end
  96.  
  97. tool.Equipped:connect(Finale)
  98. tool.Unequipped:connect(Finale)
  99. Finale()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement