Advertisement
UserOfEthanGamer

Roblox Gun Script

Feb 9th, 2020
77,518
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 1 0
  1. --Make sure it is a local script :) --
  2. -- also there is no ammo limit --
  3. local settings = {
  4. ["tooltip"] = "Produced by UserOfEthanGamer"; -- Tooltip that will pop up when the mouse is hovered over the item
  5. ["name"] = ".56 MG"; -- Name of the gun
  6. ["dtime"] = .05; -- Amount of time before a bullet disappears
  7. ["cooldown"] = .1; -- Time between shots
  8. ["rldtime"] = 1; -- Reload time
  9. ["maxammo"] = 32; -- Amount of ammo in one magazine
  10. ["damage"] = 8; -- Amount of damage one bullet does
  11. ["automatic"] = true; -- If set to true, the gun will continously fire if the left mouse button is held down
  12. ["range"] = 1500; -- Maximum distance a bullet can travel in studs
  13. ["reloadwhenout"] = true; -- Automatically reloads the weapon if your ammo is at 0
  14. }
  15.  
  16.  
  17.  
  18. db = false
  19. local rld = false
  20. local ammo = settings["maxammo"]
  21. local plr = game.Players.LocalPlayer;
  22. repeat wait() until plr.Character;
  23. local char = plr.Character;
  24. local mouse = plr:GetMouse()
  25. local tool, handle = script.Parent, script.Parent:FindFirstChild("Handle");
  26. local r = game:GetService("RunService")
  27. local hold = false
  28. local enabled = false
  29.  
  30. tool.ToolTip = settings["tooltip"]
  31. tool.Name = settings["name"].." ".."["..ammo.."]"
  32.  
  33. local function reload()
  34. if ammo <= 31 then
  35. if rld == false then rld = true
  36. if db == false then db = true
  37. tool.Reload:Play()
  38. tool.Name = "REL."
  39. wait(settings["rldtime"]/3)
  40. tool.Name = "REL.."
  41. wait(settings["rldtime"]/3)
  42. tool.Name = "REL..."
  43. wait(settings["rldtime"]/3)
  44. ammo = settings["maxammo"]
  45. tool.Name = settings["name"].." ".."["..ammo.."]"
  46. end
  47. end
  48. rld = false
  49. db = false
  50. end
  51. end
  52.  
  53.  
  54. local function FireRay()
  55. if enabled == false then return end
  56. if ammo > 0 then
  57. if db == false then db = true
  58. tool.Name = settings["name"].." ".."["..ammo.."]"
  59. tool.Shot:Play()
  60. ammo = ammo - 1
  61. local ray = Ray.new(handle.Position,(mouse.Hit.p-handle.Position).unit*settings["range"])
  62. local hit,pos = workspace:FindPartOnRay(ray,char)
  63. tool.Name = settings["name"].." ".."["..ammo.."]"
  64. if hit ~= nil then
  65. if hit.Parent:FindFirstChild("Humanoid") then
  66. hit.Parent.Humanoid:TakeDamage(settings["damage"])
  67. end
  68. end
  69. local p = Instance.new("Part",workspace)
  70. p.Anchored = true
  71. p.CanCollide = false
  72. p.Name = "Bullet"
  73. p.BrickColor = BrickColor.new("New Yeller")
  74. p.FormFactor = "Custom"
  75. p.TopSurface = "Smooth"
  76. p.BottomSurface = "Smooth"
  77. local s = (pos-handle.Position).magnitude
  78. p.Size = Vector3.new(.2,.2,s)
  79. p.CFrame = CFrame.new(pos,handle.Position)*CFrame.new(0,0,-s/2)
  80. coroutine.resume(coroutine.create(function()
  81. wait(settings["dtime"])
  82. p:Destroy()
  83. end))
  84. end
  85. end
  86. wait(settings["cooldown"])
  87. db = false
  88. if rld == true then db = true
  89. end
  90. end
  91.  
  92. tool.Equipped:connect(function(mouse2)
  93. if enabled == false then enabled = true
  94. mouse2.Icon = "rbxasset://textures\\GunCursor.png"
  95. if settings["automatic"] == true then
  96. mouse.Button1Down:connect(function()
  97. hold = true
  98. while hold do
  99. r.RenderStepped:wait()
  100. FireRay()
  101. if ammo <= 0 and settings["reloadwhenout"] == true then
  102. reload()
  103. end
  104. end
  105. end)
  106. mouse.Button1Up:connect(function()
  107. hold = false
  108. end)
  109. else
  110. mouse.Button1Down:connect(function()
  111. FireRay()
  112. if ammo <= 0 and settings["reloadwhenout"] == true then
  113. reload()
  114. end
  115. end)
  116. end
  117. end
  118. tool.Unequipped:connect(function()
  119. if enabled == true then enabled = false
  120. else
  121. return
  122. end
  123. end)
  124.  
  125. end)
  126.  
  127. mouse.KeyDown:connect(function(key)
  128. if enabled == false then return end
  129. if key:lower() == "r" then
  130. reload()
  131. end
  132. end)
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. --WARNING THIS IS A NORMAL SCRIPT--
  140. --DONT MIX THESE 2--
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156. Tool = script.Parent;
  157. local arms = nil
  158. local torso = nil
  159. local welds = {}
  160.  
  161. function Equip(mouse)
  162. wait(0.01)
  163. arms = {Tool.Parent:FindFirstChild("Left Arm"), Tool.Parent:FindFirstChild("Right Arm")}
  164. torso = Tool.Parent:FindFirstChild("Torso")
  165. if arms ~= nil and torso ~= nil then
  166. local sh = {torso:FindFirstChild("Left Shoulder"), torso:FindFirstChild("Right Shoulder")}
  167. if sh ~= nil then
  168. local yes = true
  169. if yes then
  170. yes = false
  171. sh[1].Part1 = nil
  172. sh[2].Part1 = nil
  173. local weld1 = Instance.new("Weld")
  174. weld1.Part0 = torso
  175. weld1.Parent = torso
  176. weld1.Part1 = arms[1]
  177. weld1.C1 = CFrame.new(-0.5, 0.9, 0.7) * CFrame.fromEulerAnglesXYZ(math.rad(290), 0, math.rad(-90))
  178. welds[1] = weld1
  179. local weld2 = Instance.new("Weld")
  180. weld2.Part0 = torso
  181. weld2.Parent = torso
  182. weld2.Part1 = arms[2]
  183. weld2.C1 = CFrame.new(-1, 0.6, 0.5) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-20), 0)
  184. welds[2] = weld2
  185. end
  186. else
  187. print("sh")
  188. end
  189. else
  190. print("arms")
  191. end
  192. end
  193.  
  194. function Unequip(mouse)
  195. if arms ~= nil and torso ~= nil then
  196. local sh = {torso:FindFirstChild("Left Shoulder"), torso:FindFirstChild("Right Shoulder")}
  197. if sh ~= nil then
  198. local yes = true
  199. if yes then
  200. yes = false
  201. sh[1].Part1 = arms[1]
  202. sh[2].Part1 = arms[2]
  203. welds[1].Parent = nil
  204. welds[2].Parent = nil
  205. end
  206. else
  207. print("sh")
  208. end
  209. else
  210. print("arms")
  211. end
  212. end
  213. Tool.Equipped:connect(Equip)
  214. Tool.Unequipped:connect(Unequip)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement