Advertisement
aspiringcald2223

Gun script

May 20th, 2019
4,710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.91 KB | None | 0 0
  1. wait(1)
  2. local Tool = script.Parent;
  3. local pewsound
  4. local bangsound
  5. local cam
  6. local ggui
  7. local AlertCarry = Tool.AlertCarry
  8. --
  9. enabled = true
  10. automatichold = false
  11. dmged = false
  12. shotgun = false
  13. equipped = false
  14. overheated = false
  15. isZoom = false
  16.  
  17. -----------------------------------------------------------------------------ONLY EDIT THESE VALUES!!!!!
  18. -----!Instructions!-----
  19. --Make sure you have a part in the gun named Barrel, it is where the laser will shoot from.--
  20. --Just place this script into any gun and edit the values below.--
  21. --Don't edit anything else or risk breaking it.--
  22. ------------------------
  23. Damage = math.random(25,27)
  24. SPS = 9 -- Shots Per Second, gives a limit of how fast the gun shoots.
  25. Recoil = 10 -- [1-10] [1 = Minigun, 10 = Sniper]
  26. WallShoot = false -- Shoots through walls.
  27. GH = false -- [True = RB can't hurt RB.] [False = RB can hurt RB.]
  28. BulletColor = "New Yeller" -- Any Brickcolor will work.
  29. --------------------------------------------------------------------------------------------------------
  30.  
  31. local zm = Instance.new("Part")
  32. zm.Name = "ZoomZM"
  33. zm.Anchored = true
  34. zm.Transparency = 1
  35. zm.Size = Vector3.new(1,1,1)
  36. zm.CanCollide = false
  37. GunType = 0
  38.  
  39. --[[local gui = Instance.new("ScreenGui")
  40. local bg = Instance.new("Frame",gui)
  41. local bar = Instance.new("Frame",bg)
  42. local bvl = Instance.new("ImageLabel", bg)
  43. bvl.Name = "Bevel"
  44. bvl.BackgroundTransparency = 1
  45. bvl.Image = "http://www.roblox.com/asset/?id=56852431"
  46. bvl.Size = UDim2.new(1,0,1,0)
  47. bg.Name = "Back"
  48. bar.Name = "Charge"
  49. bar.BackgroundColor3 = Color3.new(200/255,0/255,0/255)
  50. bg.BackgroundColor3 = Color3.new(200/255,200/255,200/255)
  51. bg.Size = UDim2.new(0,10,0,-100)
  52. bg.Position = UDim2.new(0,5,0,500)
  53. bar.Size = UDim2.new(0,4,-1,0)
  54. bar.Position = UDim2.new(0,3,1,0)
  55.  
  56. ggui = gui:Clone()
  57. ggui.Name = "GunGui"
  58. ggui.Back.Charge.Size = UDim2.new(0,4,-(script.Charge.Value/100),0)]]
  59.  
  60. GroupID = 5520
  61.  
  62. function AntiGH(char1,char2)
  63. if GH then
  64. local plyr1 = game.Players:findFirstChild(char1.Name)
  65. local plyr2 = game.Players:findFirstChild(char2.Name)
  66. if plyr1 and plyr2 then
  67. if plyr1:IsInGroup(GroupID) and plyr2:IsInGroup(GroupID) then
  68. return false
  69. end
  70. end
  71. return true
  72. elseif not GH then
  73. return true
  74. end
  75. end
  76.  
  77. MaxDist = 1000
  78.  
  79. function RayCast(Start,End,Ignore)
  80. if WallShoot then
  81. ray1 = Ray.new(Start, End.unit * 999.999)
  82. local Part1, TempPos = Workspace:FindPartOnRay(ray1,Ignore)
  83. ray2 = Ray.new(TempPos, End.unit * 999.999)
  84. local Part2, EndPos = Workspace:FindPartOnRay(ray2,Part1)
  85. return Part1, Part2, EndPos
  86. elseif not WallShoot then
  87. ray = Ray.new(Start, End.unit * 999.999)
  88. return Workspace:FindPartOnRay(ray,Ignore)
  89. end
  90. end
  91.  
  92. function DmgPlr(Part)
  93. if Part ~= nil then
  94. local c = Instance.new("ObjectValue")
  95. c.Name = "creator"
  96. c.Value = game.Players:findFirstChild(script.Parent.Parent.Name)
  97. local hum = Part.Parent:findFirstChild("Humanoid")
  98. local hathum = Part.Parent.Parent:findFirstChild("Humanoid")
  99. local hat = Part.Parent
  100. if hathum ~= nil and hat:IsA("Hat") and AntiGH(hathum.Parent, script.Parent.Parent) then
  101. hathum:TakeDamage(Damage/3)
  102. Part.Parent = game.Workspace
  103. Part.CFrame = CFrame.new(Part.Position + Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5)))
  104. hat:Remove()
  105. c.Parent = hathum
  106. game.Debris:AddItem(c,1.5)
  107. elseif hum ~= nil and AntiGH(hum.Parent, script.Parent.Parent) then
  108. if Part.Name == "Head" then
  109. hum:TakeDamage(Damage*2)
  110. end
  111. hum:TakeDamage(Damage)
  112. c.Parent = hum
  113. game.Debris:AddItem(c,1.5)
  114. end
  115. end
  116. end
  117.  
  118. function onButton1Down(mouse)
  119. if AlertCarry.Value == false then
  120. if script.Parent.Ammo.Value == 0 then
  121. else
  122. if GunType == 0 then
  123. if (not enabled) then return end
  124. enabled = false
  125. LaserShoot(mouse)
  126. script.Parent.Barrel.Light.Light.Visible = true
  127. script.Parent.Ammo.Value = script.Parent.Ammo.Value - 1
  128. wait(0.01)
  129. script.Parent.Barrel.Light.Light.Visible = false
  130. wait(1/SPS)
  131. enabled = true
  132. elseif GunType == 1 then
  133. automatichold = true
  134. while automatichold == true and script.Parent.Ammo.Value ~= 0 do wait()
  135. if (not enabled) then return end
  136. if AlertCarry.Value == false then
  137. enabled = false
  138. LaserShoot(mouse)
  139. script.Parent.Barrel.Light.Light.Visible = true
  140. script.Parent.Ammo.Value = script.Parent.Ammo.Value - 1
  141. wait(0.01)
  142. script.Parent.Barrel.Light.Light.Visible = false
  143. wait(1/SPS)
  144. enabled = true
  145. end
  146. end
  147. end
  148. end
  149. end
  150. end
  151.  
  152. function LaserShoot(mouse)
  153. hit = mouse.Hit.p
  154. local StartPos = script.Parent.Barrel.CFrame.p
  155. local rv = (StartPos-hit).magnitude/(Recoil * 20)
  156. local rcl = Vector3.new(math.random(-rv,rv),math.random(-rv,rv),math.random(-rv,rv))
  157. aim = hit + rcl
  158. local P = Instance.new("Part")
  159. P.Name = "Bullet"
  160. P.formFactor = 3
  161. P.BrickColor = BrickColor.new(BulletColor)
  162. P.Size = Vector3.new(0.1,0.1,0.1)
  163. P.Anchored = true
  164. P.CanCollide = false
  165. P.Transparency = 1
  166. P.Parent = script.Parent.Parent
  167. local m = Instance.new("CylinderMesh")
  168. m.Name = "Mesh"
  169. m.Parent = P
  170. local c = Instance.new("ObjectValue")
  171. c.Name = "creator"
  172. c.Value = game.Players:findFirstChild(script.Parent.Parent.Name)
  173.  
  174. script.Fire:Play()
  175.  
  176. local SPos = script.Parent.Barrel.CFrame.p
  177. if WallShoot then
  178. local Part1, Part2, EndPos = RayCast(SPos, (aim-SPos).unit * 999, script.Parent.Parent)
  179. DmgPlr(Part1)
  180. DmgPlr(Part2)
  181. if Part1 and Part2 then
  182. local enddist = (EndPos-SPos).magnitude
  183. P.CFrame = CFrame.new(EndPos, SPos) * CFrame.new(0,0,-enddist/2) * CFrame.Angles(math.rad(90),0,0)
  184. m.Scale = Vector3.new(.2,enddist,.2)
  185. else
  186. P.CFrame = CFrame.new(EndPos, SPos) * CFrame.new(0,0,-MaxDist/2) * CFrame.Angles(math.rad(90),0,0)
  187. m.Scale = Vector3.new(.2,MaxDist,.2)
  188. end
  189. elseif not WallShoot then
  190. local Part, Pos = RayCast(SPos, (aim-SPos).unit * 999, script.Parent.Parent)
  191. DmgPlr(Part)
  192. if Part then
  193. local dist = (Pos-SPos).magnitude
  194. P.CFrame = CFrame.new(Pos, SPos) * CFrame.new(0,0,-dist/2) * CFrame.Angles(math.rad(90),0,0)
  195. m.Scale = Vector3.new(.1,dist,.1)
  196. else
  197. P.CFrame = CFrame.new(Pos, SPos) * CFrame.new(0,0,-MaxDist/2) * CFrame.Angles(math.rad(90),0,0)
  198. m.Scale = Vector3.new(.1,MaxDist,.1)
  199. end
  200. end
  201. game.Debris:AddItem(P,.1)
  202. end
  203.  
  204. function onButton1Up(mouse)
  205. automatichold = false
  206. end
  207.  
  208. function onEquippedLocal(mouse)
  209. mouse.Icon = ""
  210. mouse.KeyDown:connect(onKeyDown)
  211. end
  212.  
  213. function defaultrifle()
  214. torso = Tool.Parent:FindFirstChild("Torso")
  215. if torso ~= nil then
  216. torso.weld1.C1 = CFrame.new(-0.25, -0.2, 0.5) * CFrame.fromEulerAnglesXYZ(math.rad(350), 0, math.rad(-90))
  217. torso.weld2.C1 = CFrame.new(-1, 0.3, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-15), 0)
  218. end
  219. end
  220.  
  221. function defaultpistol()
  222. torso = Tool.Parent:FindFirstChild("Torso")
  223. if torso ~= nil then
  224. torso.weld1.C1 = CFrame.new(-0.25, -0.2, 0.5) * CFrame.fromEulerAnglesXYZ(math.rad(350), 0, math.rad(-90))
  225. torso.weld2.C1 = CFrame.new(-1, 0.3, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-15), 0)
  226. end
  227. end
  228.  
  229. function holster()
  230. torso = Tool.Parent:FindFirstChild("Torso")
  231. if torso ~= nil then
  232. torso.weld1.C1 = CFrame.new(0.5,0,.5) * CFrame.fromEulerAnglesXYZ(math.rad(315), 0, math.rad(-40))
  233. torso.weld2.C1 = CFrame.new(-.8, -0.6, -0.5) * CFrame.fromEulerAnglesXYZ(math.rad(-40), math.rad(-60), 0)
  234. end
  235. end
  236.  
  237. function onKeyDown(key, mouse)
  238.  
  239.  
  240.  
  241. if key:lower() == "r" then
  242. if script.Parent.Ammo.Value ~= script.Parent.MaxAmmo.Value then
  243.  
  244. script.Reload:Play()
  245.  
  246. enabled = false
  247. repeat wait(0.05) script.Parent.Ammo.Value = script.Parent.Ammo.Value + 3 until script.Parent.Ammo.Value >= script.Parent.MaxAmmo.Value
  248. script.Parent.Ammo.Value = script.Parent.MaxAmmo.Value
  249. enabled = true
  250. end
  251. end
  252.  
  253. if key:lower() == "m" then
  254. if GunType == 1 then
  255. GunType = 0
  256. Recoil = 10
  257. else
  258. GunType = 1
  259. Recoil = 8
  260. end
  261. end
  262.  
  263. if key:lower() == "e" then
  264. if AlertCarry.Value == false then
  265. holster()
  266. AlertCarry.Value = true
  267. else
  268. defaultrifle()
  269. AlertCarry.Value = false
  270. end
  271. end
  272.  
  273. end
  274.  
  275. function onEquipped(mouse)
  276. equipped = true
  277.  
  278. if mouse == nil then
  279. print("Mouse not found")
  280. return
  281. end
  282. mouse.Icon = "http://www.roblox.com/asset/?id=70405991"
  283. mouse.Button1Down:connect(function() onButton1Down(mouse) end)
  284. mouse.Button1Up:connect(function() onButton1Up(mouse) end)
  285. mouse.KeyDown:connect(function(key) onKeyDown(key, mouse) end)
  286.  
  287. end
  288.  
  289. function onUnequipped(mouse)
  290. equipped = false
  291. automatichold = false
  292.  
  293.  
  294. end
  295.  
  296. script.Parent.Equipped:connect(onEquipped)
  297. script.Parent.Unequipped:connect(onUnequipped)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement