KrYn0MoRe

glock v2

Nov 26th, 2020 (edited)
888
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local plr,char,hum,root
  2.  
  3. plr = owner
  4. char = plr.Character
  5. hum = char:FindFirstChildOfClass("Humanoid")
  6. root = char:FindFirstChild("HumanoidRootPart")
  7. head = char:FindFirstChild("Head")
  8.  
  9. Tool0 = Instance.new("Tool")
  10. Part1 = Instance.new("Part")
  11. SpecialMesh2 = Instance.new("SpecialMesh")
  12. Tool0.Name = "G18"
  13. Tool0.Parent = nil
  14. Part1.Name = "Handle"
  15. Part1.Parent = Tool0
  16. Part1.CFrame = CFrame.new(-9.40400028, 0.49000001, -11.9640007, -1, 0, 8.74227766e-08, 0, 1, 0, -8.74227766e-08, 0, -1)
  17. Part1.Orientation = Vector3.new(0, 180, 0)
  18. Part1.Position = Vector3.new(-9.40400028, 0.49000001, -11.9640007)
  19. Part1.Rotation = Vector3.new(-180, 0, -180)
  20. Part1.Size = Vector3.new(1.44400001, 0.980000019, 0.231999993)
  21. Part1.Anchored = true
  22. Part1.BottomSurface = Enum.SurfaceType.Smooth
  23. Part1.CanCollide = false
  24. Part1.TopSurface = Enum.SurfaceType.Smooth
  25. SpecialMesh2.Parent = Part1
  26. SpecialMesh2.MeshId = "rbxassetid://543260475"
  27. SpecialMesh2.Scale = Vector3.new(0.0710000023, 0.0710000023, 0.0710000023)
  28. SpecialMesh2.TextureId = "rbxassetid://543261418"
  29. SpecialMesh2.MeshType = Enum.MeshType.FileMesh
  30.  
  31. local tool,handle
  32. tool = Tool0
  33. tool.CanBeDropped = false
  34. handle = tool:FindFirstChild("Handle")
  35.  
  36. for i,v in pairs(tool:GetChildren()) do
  37.     if v:IsA("BasePart") then
  38.         v.Anchored = false
  39.         v.CanCollide = false
  40.         v.Locked = true
  41.         if v ~= handle then
  42.             local weld = Instance.new("Weld")
  43.             weld.Part0 = handle
  44.             weld.Part1 = v
  45.             weld.C0 = handle.CFrame:Inverse()
  46.             weld.C1 = v.CFrame:Inverse()
  47.             weld.Parent = v
  48.         else
  49.             v.CanCollide = true
  50.         end
  51.     end
  52. end
  53.  
  54. tool.Parent = plr:FindFirstChildOfClass("Backpack")
  55.  
  56. local grips = {
  57.     shooting = CFrame.new(-0.335572511, -0.202204779, -0.00730848266, 1.17396892e-08, 0.17555213, -0.984470129, -2.09343809e-09, 0.984470129, 0.17555213, 1, 0, 1.19248806e-08),
  58.     equipped = CFrame.new(-0.331445694, -0.158765793, -0.00730848266, 1.19248806e-08, 0, -1, 0, 1, 0, 1, 0, 1.19248806e-08),
  59. }
  60.  
  61. tool.Grip = grips.equipped
  62.  
  63. NLS([[
  64. local plr,char,hum,root,head
  65.  
  66. function get_char()
  67.     plr = game:GetService("Players").LocalPlayer
  68.     repeat wait() until plr.Character and plr.Character.Parent
  69.     char = plr.Character
  70.     hum = char:FindFirstChild("Humanoid")
  71.     root = char:FindFirstChild("HumanoidRootPart")
  72.     head = char:FindFirstChild("Head")
  73.     if not hum or 0 >= hum.Health then
  74.         get_char()
  75.     end
  76. end
  77.  
  78. get_char()
  79.  
  80. local mouse = plr:GetMouse()
  81. local uis = game:GetService("UserInputService")
  82. local remote = game:GetService("ReplicatedStorage"):WaitForChild('gun_server_remote')
  83. local tool = script.Parent
  84.  
  85. local camera = workspace.CurrentCamera
  86.  
  87. local aim_type = 0
  88. local has_scope = false
  89. local original_sens = game:GetService("UserInputService").MouseDeltaSensitivity
  90.  
  91. local tool,handle
  92. tool = script.Parent
  93. handle = tool:WaitForChild("Handle")
  94.  
  95. local grips = {
  96.     shooting = CFrame.new(-0.335572511, -0.202204779, -0.00730848266, 1.17396892e-08, 0.17555213, -0.984470129, -2.09343809e-09, 0.984470129, 0.17555213, 1, 0, 1.19248806e-08),
  97.     equipped = CFrame.new(-0.331445694, -0.158765793, -0.00730848266, 1.19248806e-08, 0, -1, 0, 1, 0, 1, 0, 1.19248806e-08),
  98. }
  99.  
  100. tool.Grip = grips.equipped
  101.  
  102. local bulletfire = 1
  103. local firemodes = {
  104.     'i2',
  105.     'i1',
  106.     'i3'
  107. }
  108. local fmid = 0
  109. local firemode = 1 -- 1 = semi, 2 = auto, 3 = burst
  110. local shootwait = 0.04/bulletfire
  111. local boltwait = 1.5
  112. local recoil_power = 1.3
  113. local needcool = false
  114. local boltaction = false
  115. local boltaction2 = false
  116. local max_tot_ammo = 1/0
  117. local tot_ammo = max_tot_ammo
  118. local max_ammo = 18
  119. local ammo = max_ammo
  120. local recoil = 0
  121. local lastshot = 0
  122. local using = false
  123. local equipped = false
  124. local op = false
  125. local junk = workspace:WaitForChild('junk',1) or workspace
  126. local hud = nil
  127. local can_scope = true
  128. local shooting = false
  129.  
  130. --script.Parent = nil
  131.  
  132. if not script:FindFirstChild('set') then
  133.     local set = Instance.new("NumberValue",script)
  134.     set.Name = 'set'
  135.     local n1 = Instance.new("NumberValue",script)
  136.     n1.Name = 'ammo'
  137.     n1.Value = max_ammo
  138.     local n2 = Instance.new("NumberValue",script)
  139.     n2.Name = 'total_ammo'
  140.     n2.Value = max_tot_ammo
  141. else
  142.     ammo = script:FindFirstChild('ammo').Value
  143.     tot_ammo = script:FindFirstChild('total_ammo').Value
  144. end
  145.  
  146. local bullettype = 1
  147. local bullettypes = {
  148.     [1] = { -- small (smgs, pistols)
  149.         mesh = 'http://www.roblox.com/asset/?id=95387759',
  150.         texture = 'http://www.roblox.com/asset/?id=95387789',
  151.         scale = Vector3.new(1.8, 1.8, 1.8),
  152.         size = Vector3.new(0.12, 0.12, 0.21)
  153.     },
  154.     [2] = { -- medium (rifles)
  155.         mesh = 'http://www.roblox.com/asset/?id=95392019',
  156.         texture = 'http://www.roblox.com/asset/?id=95391833',
  157.         scale = Vector3.new(0.9, 0.9, 0.9),
  158.         size = Vector3.new(0.12, 0.12, 0.192)
  159.     },
  160.     [3] = { -- big (snipers, big bois)
  161.         mesh = 'http://www.roblox.com/asset/?id=94295100',
  162.         texture = 'http://www.roblox.com/asset/?id=94287792',
  163.         scale = Vector3.new(2.4, 2.4, 2.4),
  164.         size = Vector3.new(0.12, 0.12, 0.372)
  165.     },
  166.     [4] = { -- medium (shotguns)
  167.         mesh = 'http://www.roblox.com/asset/?id=94248124',
  168.         texture = 'http://www.roblox.com/asset/?id=94219470',
  169.         scale = Vector3.new(0.45, 0.45, 0.45),
  170.         size = Vector3.new(0.12, 0.12, 0.234)
  171.     },
  172. }
  173.  
  174. local libruary = {
  175.     ['wizz'] = {342190005, 342190012, 342190017, 342190024},
  176.     ['crackSmall'] = {873119768, 873119788, 873119811, 873119845, 873119886, 873119904},
  177.     ['crackBig'] = {873119597, 873119653, 873119679, 873119703, 873119724, 873119744},
  178.     ['whizz'] = {873121840, 873121858, 873121876, 873121896, 873121913, 873121936},
  179.     ['woodhit'] = {342204157, 342204164, 342204170, 342204175, 871705143, 871705174}, --871705195, 871705217, 871705237, 871705264
  180.     ['stonehit'] = {871701076, 871701134, 871701190, 871701241, 871701297, 871701346},
  181.     ['metalhit'] = {871704182, 871704259, 871704297, 871704329, 871704362, 871704395},
  182.     ['grasshit'] = {871709869, 871709832, 871709789, 871709755, 871709708, 871709643},
  183.     ['impact'] = {525720625},
  184. }
  185.  
  186. local gundata = {
  187.     ['AK-47'] = {
  188.         reload_s = 'rbxassetid://3742928054',
  189.         shoot_s = 'rbxassetid://168436671',
  190.     },
  191.     ['M4A1-S'] = {
  192.         reload_s = 'rbxassetid://2232695010',
  193.         shoot_s = 'rbxassetid://4642718673',
  194.     },
  195.     ['G18'] = {
  196.         reload_s = 'rbxassetid://2232697419',
  197.         shoot_s = 'rbxassetid://240718012',
  198.     },
  199.     ['BFG-50'] = {
  200.         reload_s = 'rbxassetid://2775805505',
  201.         shoot_s = 'rbxassetid://590136707',
  202.     },
  203.     ['SSG-08'] = {
  204.         reload_s = 'rbxassetid://4649193317',
  205.         shoot_s = 'rbxassetid://4649186576',
  206.     },
  207. }
  208.  
  209. gundata = gundata[tool.Name]
  210.  
  211. local equip = Instance.new("Sound")
  212. equip.SoundId = 'rbxassetid://769464514'
  213. equip.Volume = 0.8
  214. equip.Parent = handle
  215.  
  216. local reload_s = Instance.new("Sound")
  217. reload_s.SoundId = gundata.reload_s
  218. reload_s.Volume = 0.7
  219. reload_s.Parent = handle
  220.  
  221. local wbreak_s = Instance.new("Sound")
  222. wbreak_s.SoundId = "rbxassetid://627558611"
  223. wbreak_s.Volume = 0.7
  224. wbreak_s.Parent = handle
  225.  
  226. local empty_s = Instance.new("Sound")
  227. empty_s.SoundId = 'rbxassetid://132464034'
  228. empty_s.Volume = 0.7
  229. empty_s.Parent = handle
  230.  
  231. local mode_s = Instance.new("Sound")
  232. mode_s.SoundId = 'rbxassetid://4581285291'
  233. mode_s.Volume = 0.7
  234. mode_s.Parent = handle
  235.  
  236. local shoot_s = Instance.new("Sound")
  237. shoot_s.Name = 'shoot'
  238. shoot_s.SoundId = gundata.shoot_s
  239. shoot_s.Volume = 1
  240. shoot_s.Parent = handle
  241.  
  242. local effect_part = Instance.new("Part")
  243. local smoke = Instance.new("ParticleEmitter")
  244. local flash = Instance.new("ParticleEmitter")
  245. local light = Instance.new("PointLight")
  246. effect_part.Name = "effect"
  247. effect_part.Parent = tool
  248. effect_part.CFrame = CFrame.new(-14.3099976, 2.64201403, -6.57999992)
  249. effect_part.Transparency = 1
  250. effect_part.Size = Vector3.new(0.100000001, 0.100000001, 0.100000001)
  251. effect_part.BottomSurface = Enum.SurfaceType.Smooth
  252. effect_part.CanCollide = false
  253. effect_part.TopSurface = Enum.SurfaceType.Smooth
  254. smoke.Name = "smoke"
  255. smoke.Parent = effect_part
  256. smoke.Speed = NumberRange.new(5, 7)
  257. smoke.Rotation = NumberRange.new(0, 360)
  258. smoke.Color = ColorSequence.new(Color3.new(0.27451, 0.27451, 0.27451),Color3.new(0.27451, 0.27451, 0.27451))
  259. smoke.Enabled = false
  260. smoke.LightEmission = 0.10000000149012
  261. smoke.Texture = "http://www.roblox.com/asset/?id=244514423"
  262. smoke.Transparency = NumberSequence.new(0.60000002384186,1)
  263. smoke.Size = NumberSequence.new(0.99999964237213,3)
  264. smoke.Lifetime = NumberRange.new(1.25, 1.5)
  265. smoke.Rate = 100
  266. smoke.RotSpeed = NumberRange.new(10, 10)
  267. smoke.SpreadAngle = Vector2.new(15, 15)
  268. smoke.VelocitySpread = 15
  269. flash.Name = "flash"
  270. flash.Parent = effect_part
  271. flash.Speed = NumberRange.new(0, 0)
  272. flash.Rotation = NumberRange.new(0, 90)
  273. flash.Color = ColorSequence.new(Color3.new(1, 1, 0.498039),Color3.new(1, 1, 0.498039))
  274. flash.Enabled = false
  275. flash.LightEmission = 1
  276. flash.Texture = "http://www.roblox.com/asset/?id=3419963"
  277. flash.Transparency = NumberSequence.new(0.75,1)
  278. flash.Size = NumberSequence.new(0.20000000298023,0.20000000298023)
  279. flash.Lifetime = NumberRange.new(0.050000000745058, 0.075000002980232)
  280. flash.Speed = NumberRange.new(50,50)
  281. flash.Rate = 1000
  282. light.Name = "light"
  283. light.Parent = effect_part
  284. light.Color = Color3.new(1, 1, 0.498039)
  285. light.Enabled = false
  286. light.Range = 6
  287. light.Brightness = 10
  288. light.Shadows = true
  289.  
  290. local weld = Instance.new("Weld")
  291. weld.Part0 = handle
  292. weld.Part1 = effect_part
  293. weld.C0 = weld.C0 * CFrame.new((handle.Size.X/2),0.35,0) * CFrame.Angles(math.rad(0),math.rad(0),math.rad(-90))
  294. weld.Parent = effect_part
  295.  
  296. local chamber_part = tool:FindFirstChild("chamber") or handle
  297.  
  298. local mag = tool:FindFirstChild("Mag")
  299.  
  300. if not mag then
  301.     mag = Instance.new("Part")
  302.     mag.Name = 'gun mag'
  303.     mag.Size = Vector3.new(0.48, 0.8, 0.14)
  304.     mag.Color = handle.Color
  305.     mag.CFrame = handle.CFrame * CFrame.new(0.1,-0.1,0)
  306. end
  307.  
  308. function change_firemode()
  309.     mode_s:Play()
  310.     fmid = fmid + 1
  311.     if fmid > #firemodes then
  312.         fmid = 1
  313.     end
  314.     firemode = tonumber(string.sub(firemodes[fmid],2,2))
  315.     if firemode == 3 then
  316.         bulletfire = 3
  317.     else
  318.         bulletfire = 1
  319.     end
  320. end
  321.  
  322. change_firemode()
  323.  
  324. function togglebolt(mode)
  325.     if mode == 'back' then
  326.         for i,v in pairs(tool:GetChildren()) do
  327.             if v.Name == 'Bolt' then
  328.                 v.Transparency = 1
  329.             elseif v.Name == 'BoltBack' then
  330.                 v.Transparency = 0
  331.             end
  332.         end
  333.     elseif mode == 'normal' then
  334.         for i,v in pairs(tool:GetChildren()) do
  335.             if v.Name == 'Bolt' then
  336.                 v.Transparency = 0
  337.             elseif v.Name == 'BoltBack' then
  338.                 v.Transparency = 1
  339.             end
  340.         end
  341.     end
  342. end
  343.  
  344. function usefx()
  345.     spawn(function()
  346.         local mode = true
  347.         light.Enabled = mode
  348.         flash.Enabled = mode
  349.         smoke.Enabled = mode
  350.         if not boltaction and not boltaction2 then
  351.             togglebolt('back')
  352.         end
  353.         wait()
  354.         mode = false
  355.         if not boltaction and not boltaction2 then
  356.             togglebolt('normal')
  357.         end
  358.         light.Enabled = mode
  359.         flash.Enabled = mode
  360.         smoke.Enabled = mode
  361.     end)
  362. end
  363.  
  364. function alive(c)
  365.     if c and c:FindFirstChildOfClass("Humanoid") and c:FindFirstChildOfClass("Humanoid").Health > 0 and (c:FindFirstChild("HumanoidRootPart") or c:FindFirstChild("Torso")) and c:FindFirstChild("Head") then
  366.         return true
  367.     end
  368.     return false
  369. end
  370.  
  371. function exists(c)
  372.     if c and c:FindFirstChildOfClass("Humanoid") and (c:FindFirstChild("HumanoidRootPart") or c:FindFirstChild("Torso")) and c:FindFirstChild("Head") then
  373.         return true
  374.     end
  375.     return false
  376. end
  377.  
  378. function reload()
  379.     if max_ammo > ammo then else return end
  380.     if 0 >= tot_ammo then
  381.         remote:FireServer({
  382.             tool = tool,
  383.         },'empty')
  384.         return
  385.     end
  386.     aim_type = 0
  387.     aim()
  388.     can_scope = false
  389.     using = true
  390.     reloading = true
  391.     remote:FireServer({
  392.         tool = tool,
  393.     },'reload')
  394.     if boltaction or boltaction2 then
  395.         togglebolt('back')
  396.         spawn(function()
  397.             wait(0.2)
  398.             drop_shell()
  399.         end)
  400.     end
  401.     if not boltaction then
  402.         local m = mag:Clone()
  403.         m.CanCollide = true
  404.         pcall(function()
  405.             m:FindFirstChild("Weld"):Destroy()
  406.         end)
  407.         m.Parent = junk
  408.         game:GetService("Debris"):AddItem(m,10)
  409.     end
  410.     mag.Transparency = 1
  411.     wait(reload_s.TimeLength)
  412.     if max_ammo >= tot_ammo then
  413.         ammo = ammo + tot_ammo
  414.         tot_ammo = 0
  415.         if ammo > max_ammo then
  416.             local reserve = ammo-max_ammo
  417.             ammo = ammo - reserve
  418.             tot_ammo = tot_ammo + reserve
  419.         end
  420.     elseif tot_ammo > max_ammo then
  421.         ammo = ammo + max_ammo
  422.         tot_ammo = tot_ammo - max_ammo
  423.         if ammo > max_ammo then
  424.             local reserve = ammo-max_ammo
  425.             ammo = ammo - reserve
  426.             tot_ammo = tot_ammo + reserve
  427.         end
  428.     end
  429.     script:FindFirstChild('ammo').Value = ammo
  430.     script:FindFirstChild('total_ammo').Value = tot_ammo
  431.     if equipped then
  432.         if hud then
  433.             hud.ammo.Text = ammo .. '/' .. tot_ammo
  434.         end
  435.     end
  436.     if boltaction2 then
  437.         togglebolt('normal')
  438.     end
  439.     if not boltaction then
  440.         mag.Transparency = 0
  441.     end
  442.     reloading = false
  443.     using = false
  444.     can_scope = true
  445. end
  446.  
  447. function drop_shell()
  448.     local Shell = Instance.new("Part")
  449.     Shell.Color = Color3.new(1, 1, 0)
  450.     Shell.BottomSurface = Enum.SurfaceType.Smooth
  451.     Shell.BrickColor = BrickColor.new("New Yeller")
  452.     Shell.Material = Enum.Material.Metal
  453.     Shell.Shape = Enum.PartType.Cylinder
  454.     Shell.CFrame = chamber_part.CFrame
  455.     local bt = bullettypes[bullettype]
  456.     local mesh = Instance.new("SpecialMesh")
  457.     mesh.MeshId = bt.mesh
  458.     mesh.TextureId = bt.texture
  459.     mesh.Scale = bt.scale
  460.     mesh.Parent = Shell
  461.     Shell.Size = bt.size
  462.     Shell.Parent = junk
  463.     local bvs = Instance.new("BodyVelocity")
  464.     bvs.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
  465.     bvs.Velocity = ((chamber_part.CFrame.lookVector*1)+Vector3.new(0,2,0))*5
  466.     bvs.Parent = Shell
  467.     game:GetService("Debris"):AddItem(bvs,0.1)
  468.     game:GetService("Debris"):AddItem(Shell,10)
  469. end
  470.  
  471. function raycast(Pos, Dir, Max, Ignore)
  472.     local rayparams = RaycastParams.new()
  473.     rayparams.FilterType = Enum.RaycastFilterType.Blacklist
  474.     rayparams.FilterDescendantsInstances = Ignore
  475.     rayparams.IgnoreWater = true
  476.     return workspace:Raycast(Pos, Dir * (Max or 999.999), rayparams)
  477. end
  478.  
  479. function break_window(hit)
  480.     if hit.Material == Enum.Material.Glass and hit.Name ~= 'window shatter' and hit.Name ~= 'blood' and hit.Name ~= 'blood_drop' then else return end
  481.     hit.Name = ''
  482.     remote:FireServer({
  483.         tool = tool,
  484.     },'break')
  485.     local sx,sy,sz = hit.Size.x,hit.Size.y,hit.Size.z
  486.     for x = 1,4 do
  487.         for y = 1,4 do
  488.             local part = hit:Clone()
  489.             local position = Vector3.new(x-2.1,y-2.1,0)*Vector3.new(sx/4,sy/4,sz)
  490.             part.Size = Vector3.new(sx/4,sy/4,sz)
  491.             part.CFrame = hit.CFrame*(CFrame.new(part.Size/8)-hit.Size/8+position)         
  492.             part.Velocity = Vector3.new(math.random(-10,10),math.random(-10,10),math.random(-10,10))
  493.             part.Name = "window shatter"
  494.             part.Parent = hit.Parent
  495.             game:GetService("Debris"):AddItem(part,2)
  496.             spawn(function()
  497.                 wait(0.5)
  498.                 for i = 1,10 do
  499.                     part.Transparency = part.Transparency+0.05
  500.                     wait(0.05)
  501.                 end
  502.                 part:Destroy()
  503.             end)
  504.             part.Anchored = false
  505.         end
  506.     end
  507.     hit:Destroy()
  508. end
  509.  
  510. function make_hole(pos,obj,col)
  511.     local BulletHolePart = Instance.new("Part")
  512.     BulletHolePart.Massless = true
  513.     BulletHolePart.Anchored = false
  514.     BulletHolePart.CanCollide = false
  515.     BulletHolePart.Locked = true
  516.     BulletHolePart.FormFactor = "Custom"
  517.     BulletHolePart.TopSurface, BulletHolePart.BottomSurface, BulletHolePart.RightSurface, BulletHolePart.LeftSurface, BulletHolePart.FrontSurface, BulletHolePart.BackSurface = "SmoothNoOutlines", "SmoothNoOutlines", "SmoothNoOutlines", "SmoothNoOutlines", "SmoothNoOutlines", "SmoothNoOutlines"
  518.     BulletHolePart.Name = "Bullet Hole"
  519.     BulletHolePart.Material = "Plastic"
  520.     BulletHolePart.Reflectance = 0
  521.     BulletHolePart.Transparency = 1
  522.     BulletHolePart.BrickColor = BrickColor.new("Medium stone grey")
  523.     BulletHolePart.Size = Vector3.new(0.3, 0, 0.3)
  524.     BulletHolePart:BreakJoints()
  525.     BulletHolePart.CFrame = pos
  526.     BulletHolePart.Parent = junk
  527.     local weld = Instance.new("WeldConstraint")
  528.     weld.Part0 = obj
  529.     weld.Part1 = BulletHolePart
  530.     weld.Parent = obj
  531.     game:GetService("Debris"):AddItem(BulletHolePart, 5)
  532.     local BulletHoleDecal = Instance.new("Decal")
  533.     BulletHoleDecal.Color3 = Color3.new(col.r, col.g, col.b)
  534.     BulletHoleDecal.Face = "Top"
  535.     BulletHoleDecal.Texture = "rbxassetid://359667865"
  536.     BulletHoleDecal.Transparency = 0
  537.     BulletHoleDecal.Parent = BulletHolePart
  538.     return BulletHolePart
  539. end
  540.  
  541. function fire(dir,t,ignore)
  542.     local p1 = head.Position
  543.     local p2 = (dir-p1).Unit
  544.     local result = raycast(p1, p2, 1000, ignore)
  545.  
  546.     remote:FireServer({
  547.         hitpos = mouse.Hit.p,
  548.         tool = tool,
  549.     },'shoot')
  550.     if result then
  551.         local hitrot = result.Normal
  552.         local hitpos = result.Position
  553.         local obj = result.Instance
  554.         local targplr,targchar,targhum,targtorso,targhead
  555.  
  556.         targchar = obj.Parent
  557.         targplr = game:GetService("Players"):GetPlayerFromCharacter(targchar)
  558.         for i,v in pairs(game:GetService("Players"):GetPlayers()) do
  559.             if v.Character and obj:IsDescendantOf(v.Character) then
  560.                 targchar = v.Character
  561.                 break
  562.             end
  563.         end
  564.         targhum = targchar:FindFirstChildOfClass("Humanoid")
  565.         targtorso = targchar:FindFirstChild("Torso") or targchar:FindFirstChild("UpperTorso") or targchar:FindFirstChild("HumanoidRootPart")
  566.         targhead = targchar:FindFirstChild("Head")
  567.  
  568.         if exists(targchar) and targchar ~= char then
  569.             if not obj:FindFirstChild('Dismembered') then
  570.                 local dmg = 0
  571.                 if obj.Name == 'Head' then
  572.                     dmg = math.random(15,17)
  573.                 elseif obj == targtorso or obj == targchar:FindFirstChild("HumanoidRootPart") then
  574.                     dmg = math.random(12,14)
  575.                 else
  576.                     dmg = math.random(7,11)
  577.                 end
  578.                 remote:FireServer({
  579.                     targhum = targhum,
  580.                     targchar = targchar,
  581.                     targtorso = targtorso,
  582.                     targplr = targplr,
  583.                     targhead = targhead,
  584.                     obj = obj,
  585.                     dmg = dmg,
  586.                     p1 = p1,
  587.                     p2 = p2,
  588.                     hitpos = hitpos,
  589.                     tool = tool,
  590.                 },'dmg')
  591.             end
  592.         else
  593.             local soundfont=({
  594.                 Brick="stonehit";
  595.                 Cobblestone="stonehit";
  596.                 Concrete="stonehit";
  597.                 CorrodedMetal="metalhit";
  598.                 DiamondPlate="metalhit";
  599.                 Fabric=nil;
  600.                 Foil="metalhit";
  601.                 Granite="stonehit";
  602.                 Grass="grasshit";
  603.                 Ice="stonehit";
  604.                 Marble="stonehit";
  605.                 Metal="metalhit";
  606.                 Neon=nil;
  607.                 Pebble="stonehit";
  608.                 Plastic="metalhit";
  609.                 Sand=nil;
  610.                 Slate="stonehit";
  611.                 SmoothPlastic="metalhit";
  612.                 Wood="woodhit";
  613.                 WoodPlanks="woodhit";
  614.             })[obj.Material.Name]
  615.             local bhole = make_hole(CFrame.new(hitpos, hitpos - hitrot) * CFrame.Angles(math.rad(90), math.rad(0), math.rad(0)) * CFrame.Angles(math.rad(0), math.rad(math.random(-360, 360)), math.rad(0)), obj, obj.BrickColor)
  616.             local BulletHoleSound = Instance.new("Sound")
  617.             BulletHoleSound.Volume = 0.5
  618.             BulletHoleSound.Pitch = math.random(9,11)/10
  619.             if soundfont ~= nil then
  620.                 BulletHoleSound.SoundId = "rbxassetid://"..libruary[soundfont][math.random(1,6)]
  621.             else
  622.                 BulletHoleSound.SoundId = "rbxassetid://"..libruary['impact'][1]
  623.             end
  624.             BulletHoleSound.Parent = bhole
  625.             BulletHoleSound:Play()
  626.             break_window(obj)
  627.         end
  628.         local nt = ignore
  629.         table.insert(nt,1,obj)
  630.         if 3 >= t then
  631.             fire(hitpos,t+1,nt)
  632.         end
  633.     end
  634. end
  635.  
  636. function shoot()
  637.     aim_type = 0
  638.     aim()
  639.     using = true
  640.     can_scope = false
  641.     for i = 1,bulletfire do
  642.         local mousepos = mouse.Hit.p
  643.         if 0 >= ammo then
  644.             using = false
  645.             reload()
  646.             return
  647.         end
  648.         lastshot = tick()
  649.         game:GetService("TweenService"):Create(tool,TweenInfo.new(0.2),{
  650.             Grip = grips.shooting
  651.         }):Play()
  652.         if not op then
  653.             ammo = ammo - 1
  654.         end
  655.         if hud then
  656.             hud.ammo.Text = ammo .. '/' .. tot_ammo
  657.         end
  658.         usefx()
  659.         if not boltaction and not boltaction2 then
  660.             drop_shell()
  661.         end
  662.         cam_recoil()
  663.         --
  664.  
  665.         local ignore = {char,junk}
  666.         for _,p in ipairs(game:GetService("Players"):GetPlayers()) do
  667.             if p.Character then
  668.                 for i,v in ipairs(p.Character:GetChildren()) do
  669.                     if v:IsA("Accessory") or v:IsA("Tool") then
  670.                         table.insert(ignore,1,v)
  671.                     end
  672.                 end
  673.             end
  674.         end
  675.         fire(mousepos,1,ignore)
  676.  
  677.         --
  678.         if not op then
  679.             wait(shootwait)
  680.         else
  681.             wait(0)
  682.         end
  683.         game:GetService("TweenService"):Create(tool,TweenInfo.new(0.2),{
  684.             Grip = grips.equipped
  685.         }):Play()
  686.     end
  687.     if boltaction2 and ammo > 0 then
  688.         togglebolt('back')
  689.         spawn(function()
  690.             wait(0.2)
  691.             drop_shell()
  692.         end)
  693.     end
  694.     if not op and needcool then
  695.         wait(boltwait*bulletfire)
  696.     end
  697.     if boltaction2 and ammo > 0 then
  698.         togglebolt('normal')
  699.     end
  700.     can_scope = true
  701.     using = false
  702. end
  703.  
  704. tool.Equipped:Connect(function()
  705.     equipped = true
  706.     remote:FireServer({
  707.         tool = tool,
  708.     },'equip')
  709.     ammo = script:FindFirstChild('ammo').Value
  710.     tot_ammo = script:FindFirstChild('total_ammo').Value
  711.     if not alive(char) then return end
  712.     if hud then
  713.         hud.ammo.Visible = true
  714.         hud.ammo.Text = ammo .. '/' .. tot_ammo
  715.     end
  716. end)
  717.  
  718. tool.Unequipped:Connect(function()
  719.     equipped = false
  720.     aim_type = 0
  721.     aim()
  722.     equip:Stop()
  723.     script:FindFirstChild('ammo').Value = ammo
  724.     script:FindFirstChild('total_ammo').Value = tot_ammo
  725.     if hud then
  726.         hud.ammo.Visible = false
  727.         hud.ammo.Text = '0/0'
  728.     end
  729. end)
  730.  
  731. hum.Died:Connect(function()
  732.     aim_type = 0
  733.     aim()
  734.     script:FindFirstChild('ammo').Value = ammo
  735.     script:FindFirstChild('total_ammo').Value = tot_ammo
  736.     if hud then
  737.         hud.ammo.Visible = false
  738.         hud.ammo.Text = '0/0'
  739.     end
  740.     tool:Destroy()
  741. end)
  742.  
  743. function cam_recoil()
  744.     spawn(function()
  745.         local r = 1000/recoil_power
  746.         local r2 = r/3
  747.         local x = (math.random(r/10,r)/r2)/(r/4) -- real y
  748.         local y = (math.random(-r,r)/r2)/(r/3) -- fake y
  749.         local z = (math.random(-r,r)/r2)/(r/4)
  750.         local t = 0.1
  751.         local m = 60
  752.         for i = t*m,1,-1 do
  753.             local ct = m/m/i
  754.             camera.CFrame = camera.CFrame * CFrame.fromEulerAnglesXYZ(x*ct,y*ct,z*ct)
  755.             game:GetService("RunService").RenderStepped:Wait()
  756.         end
  757.     end)
  758. end
  759.  
  760. function aim()
  761.     if can_scope and has_scope then
  762.         local pgui = plr:FindFirstChildOfClass("PlayerGui")
  763.         local aim_ui = pgui:FindFirstChild('scope')
  764.         local dof = game:GetService("Lighting"):FindFirstChild("DepthOfField")
  765.         remote:FireServer({
  766.             tool = tool,
  767.         },'aim')
  768.         if aim_type == 0 then
  769.             --hum.WalkSpeed = 16
  770.             if aim_ui then
  771.                 aim_ui:Destroy()
  772.             end
  773.             game:GetService("TweenService"):Create(dof,TweenInfo.new(0.25),{InFocusRadius = 100}):Play()
  774.             game:GetService("UserInputService").MouseDeltaSensitivity = original_sens
  775.             game:GetService("TweenService"):Create(camera,TweenInfo.new(0.25),{FieldOfView = 70}):Play()
  776.         elseif aim_type == 1 then
  777.             --hum.WalkSpeed = 10
  778.             if not aim_ui then
  779.                 aim_ui = script.scope:Clone()
  780.                 aim_ui.Parent = pgui
  781.             end
  782.             game:GetService("TweenService"):Create(dof,TweenInfo.new(0.25),{InFocusRadius = 140}):Play()
  783.             game:GetService("UserInputService").MouseDeltaSensitivity = original_sens/3
  784.             game:GetService("TweenService"):Create(camera,TweenInfo.new(0.25),{FieldOfView = 20}):Play()
  785.         elseif aim_type == 2 then
  786.             --hum.WalkSpeed = 8
  787.             if not aim_ui then
  788.                 aim_ui = script.scope:Clone()
  789.                 aim_ui.Parent = pgui
  790.             end
  791.             game:GetService("TweenService"):Create(dof,TweenInfo.new(0.25),{InFocusRadius = 200}):Play()
  792.             game:GetService("UserInputService").MouseDeltaSensitivity = original_sens/5
  793.             game:GetService("TweenService"):Create(camera,TweenInfo.new(0.25),{FieldOfView = 10}):Play()
  794.         end
  795.     end
  796. end
  797.  
  798. function handle_request(mode)
  799.     if alive(char) and not reloading and equipped and not using then
  800.         if mode == 1 then -- shoot
  801.             if firemode == 1 then -- semi
  802.                 shoot()
  803.             elseif firemode == 2 then -- auto
  804.                 while shooting and equipped do
  805.                     shoot()
  806.                     wait(shootwait)
  807.                 end
  808.             elseif firemode == 3 then -- burst
  809.                 shoot()
  810.             end
  811.         elseif mode == 2 then -- reload
  812.             reload()
  813.         end
  814.     end
  815. end
  816.  
  817. uis.InputBegan:Connect(function(input,gamepress)
  818.     if not gamepress and equipped and not reloading and not using and alive(char) then else return end
  819.     local mode = 0
  820.     if input.UserInputType == Enum.UserInputType.Keyboard then
  821.         local key = input.KeyCode
  822.         if key == Enum.KeyCode.R then
  823.             mode = 2
  824.         elseif key == Enum.KeyCode.V then
  825.             change_firemode()
  826.         end
  827.     elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
  828.         shooting = true
  829.         mode = 1
  830.     elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
  831.         aim_type = aim_type + 1
  832.         if aim_type > 2 then
  833.             aim_type = 0
  834.         end
  835.         aim()
  836.     end
  837.     handle_request(mode)
  838. end)
  839.  
  840. uis.InputEnded:Connect(function(input,gamepress)
  841.     if gamepress then return end
  842.     if input.UserInputType == Enum.UserInputType.MouseButton1 then
  843.         shooting = false
  844.     end
  845. end)
  846.  
  847. local crackSmall = {
  848.     873119768, 873119788, 873119811, 873119845, 873119886, 873119904
  849. }
  850. local crackBig = {
  851.     873119597, 873119653, 873119679, 873119703, 873119724, 873119744
  852. }
  853. local whizz = {
  854.     873121840, 873121858, 873121876, 873121896, 873121913, 873121936
  855. }
  856.  
  857. function suppress(dist)
  858.     local max = 30
  859.     local mid = max/3*2
  860.     local min = max/3
  861.     if max >= dist then
  862.         if min >= dist then
  863.             local sound = Instance.new("Sound",workspace)
  864.             sound.SoundId = 'rbxassetid://' .. crackBig[math.random(1,#crackBig)]
  865.             sound.Volume = min/dist
  866.             sound:Play()
  867.             game:GetService("Debris"):AddItem(sound,5)
  868.         elseif mid >= dist then
  869.             local sound = Instance.new("Sound",workspace)
  870.             sound.SoundId = 'rbxassetid://' .. crackSmall[math.random(1,#crackSmall)]
  871.             sound.Volume = mid/dist
  872.             sound:Play()
  873.             game:GetService("Debris"):AddItem(sound,5)
  874.         elseif max >= dist then
  875.             local sound = Instance.new("Sound",workspace)
  876.             sound.SoundId = 'rbxassetid://' .. whizz[math.random(1,#whizz)]
  877.             sound.Volume = max/dist
  878.             sound:Play()
  879.             game:GetService("Debris"):AddItem(sound,5)
  880.         end
  881.         spawn(function()
  882.             local r = 6000*(math.clamp(dist,0,max)/max)
  883.             local r2 = r/3
  884.             local x = (math.random(-r,r)/r2)/(r/4) -- real y
  885.             local y = (math.random(-r,r)/r2)/(r/3) -- fake y
  886.             local z = (math.random(-r,r)/r2)/(r/4)
  887.             local t = 0.1
  888.             local m = 60
  889.             for i = t*m,1,-1 do
  890.                 local ct = m/m/i
  891.                 camera.CFrame = camera.CFrame * CFrame.fromEulerAnglesXYZ(x*ct,y*ct,z*ct)
  892.                 game:GetService("RunService").RenderStepped:Wait()
  893.             end
  894.         end)
  895.     end
  896. end
  897.  
  898. remote.OnClientEvent:Connect(function(data,mode)
  899.     if mode == 'shoot' then
  900.         local plr = data.plr
  901.         local hitpos = data.hitpos
  902.         local handle = data.handle
  903.         if plr ~= game:GetService("Players").LocalPlayer then
  904.             local campos = camera.CFrame.p
  905.             local dist = (campos-hitpos).Magnitude
  906.             suppress(dist)
  907.         end
  908.     end
  909. end)
  910. ]],tool)
RAW Paste Data