Guest User

For Good Guys at ScriptingHelpers

a guest
Jun 30th, 2018
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 110.33 KB | None | 0 0
  1. --[[
  2. Kit By TurboFusion
  3. Remake By MuYhEt & Xander521
  4. --]]
  5. --------------------------------------------------------------------------------------
  6. --------------------[ CHARACTER LOADING ]---------------------------------------------
  7. --------------------------------------------------------------------------------------
  8.  
  9. repeat wait() until game.Players.LocalPlayer.Character
  10. repeat wait() until game.Players.LocalPlayer.Character:IsDescendantOf(game.Workspace)
  11. wait(1 / 20)
  12.  
  13. --------------------------------------------------------------------------------------
  14. --------------------[ IGNORE MODEL ]--------------------------------------------------
  15. --------------------------------------------------------------------------------------
  16.  
  17. local ignoreCode = script:WaitForChild("ignoreCode")
  18.  
  19. repeat wait() until ignoreCode.Value ~= 0
  20.  
  21. local ignoreModel = game.Workspace:WaitForChild("ignoreModel_"..ignoreCode.Value)
  22.  
  23. local grenadeFolder = ignoreModel:WaitForChild("grenadeFolder")
  24.  
  25. --------------------------------------------------------------------------------------
  26. --------------------[ CONSTANTS ]-----------------------------------------------------
  27. --------------------------------------------------------------------------------------
  28.  
  29. local Gun = script.Parent
  30. local serverMain = Gun:WaitForChild("serverMain")
  31. local Handle = Gun:WaitForChild("Handle")
  32. local AimPart = Gun:WaitForChild("AimPart")
  33. local Main = Gun:WaitForChild("Main")
  34.  
  35. local Ammo = Gun:WaitForChild("Ammo")
  36. local ClipSize = Gun:WaitForChild("ClipSize")
  37. local StoredAmmo = Gun:WaitForChild("StoredAmmo")
  38.  
  39. local createTweenIndicator = serverMain:WaitForChild("createTweenIndicator")
  40. local deleteTweenIndicator = serverMain:WaitForChild("deleteTweenIndicator")
  41. local getWeldCF = serverMain:WaitForChild("getWeldCF")
  42. local gunSetup = serverMain:WaitForChild("gunSetup")
  43. local lerpCF = serverMain:WaitForChild("lerpCF")
  44. local createBlood = serverMain:WaitForChild("createBlood")
  45. local createBulletImpact = serverMain:WaitForChild("createBulletImpact")
  46. local createShockwave = serverMain:WaitForChild("createShockwave")
  47. local createTrail = serverMain:WaitForChild("createTrail")
  48.  
  49. local Particle = require(script:WaitForChild("Particle"))
  50. local Spring = require(script:WaitForChild("Spring"))
  51. local Anims = require(Gun:WaitForChild("ANIMATIONS"))
  52. local Plugins = require(Gun:WaitForChild("PLUGINS"))
  53. local S = require(Gun:WaitForChild("SETTINGS"))
  54.  
  55. local Player = game.Players.LocalPlayer
  56. local Char = Player.Character
  57. local Humanoid = Char:WaitForChild("Humanoid")
  58. local Torso = Char:WaitForChild("Torso")
  59. local Head = Char:WaitForChild("Head")
  60. local HRP = Char:WaitForChild("HumanoidRootPart")
  61. local Root = HRP:WaitForChild("RootJoint")
  62.  
  63. local Neck = Torso:WaitForChild("Neck")
  64.  
  65. local LArm = Char:WaitForChild("Left Arm")
  66. local RArm = Char:WaitForChild("Right Arm")
  67. local LLeg = Char:WaitForChild("Left Leg")
  68. local RLeg = Char:WaitForChild("Right Leg")
  69.  
  70. local M2 = Player:GetMouse()
  71.  
  72. local mainGUI = script:WaitForChild("mainGUI")
  73.    
  74. local crossHair = mainGUI:WaitForChild("crossHair")
  75. local HUD = mainGUI:WaitForChild("HUD")
  76. local Scope = mainGUI:WaitForChild("Scope")
  77. local fireSelect = mainGUI:WaitForChild("fireSelect")
  78. local hitMarker = mainGUI:WaitForChild("hitMarker")
  79. local Sens = mainGUI:WaitForChild("Sens")
  80.  
  81. local crossA = crossHair:WaitForChild("A"):WaitForChild("Line")
  82. local crossB = crossHair:WaitForChild("B"):WaitForChild("Line")
  83. local crossC = crossHair:WaitForChild("C"):WaitForChild("Line")
  84. local crossD = crossHair:WaitForChild("D"):WaitForChild("Line")
  85.  
  86. local Controls = HUD:WaitForChild("Controls")
  87.  
  88. local gunNameTitle = HUD:WaitForChild("gunName"):WaitForChild("Title")
  89.  
  90. local scopeMain = Scope:WaitForChild("Main")
  91. local scopeSteady = Scope:WaitForChild("Steady")
  92.  
  93. local fireModes = fireSelect:WaitForChild("Modes")
  94.  
  95. local modeGUI = HUD:WaitForChild("Mode"):WaitForChild("Main")
  96. local clipAmmoGUI = HUD:WaitForChild("Ammo"):WaitForChild("Clip")
  97. local storedAmmoGUI = HUD:WaitForChild("Ammo"):WaitForChild("Stored")
  98.  
  99. local DS = game:GetService("Debris")
  100. local CP = game:GetService("ContentProvider")
  101. local RS = game:GetService("RunService")
  102. local UIS = game:GetService("UserInputService")
  103.  
  104. local Cam = game.Workspace.CurrentCamera
  105.  
  106. local ABS, HUGE, FLOOR, CEIL = math.abs, math.huge, math.floor, math.ceil
  107. local RAD, SIN, COS, TAN = math.rad, math.sin, math.cos, math.tan
  108. local VEC2, V3 = Vector2.new, Vector3.new
  109. local CF, CFANG = CFrame.new, CFrame.Angles
  110. local INSERT = table.insert
  111.  
  112. local maxStamina = S.sprintTime * 60
  113. local maxSteadyTime = S.scopeSettings.steadyTime * 60
  114.  
  115. local LethalIcons = {
  116.     "http://www.roblox.com/asset/?id=194849880";
  117.     "http://www.roblox.com/asset/?id=195727791";
  118.     "http://www.roblox.com/asset/?id=195728137";
  119.     "http://www.roblox.com/asset/?id=218151830";
  120. }
  121.  
  122. local TacticalIcons = {
  123.     "http://www.roblox.com/asset/?id=195728473";
  124.     "http://www.roblox.com/asset/?id=195728693";
  125. }
  126.  
  127. local ASCII = {
  128.     071; 117; 110; 032;
  129.     075; 105; 116; 032;
  130.     115; 099; 114; 105;
  131.     112; 116; 101; 100;
  132.     032; 098; 121; 032;
  133.     084; 117; 114; 098;
  134.     111; 070; 117; 115;
  135.     105; 111; 110; 000;
  136. }
  137.  
  138. local Ignore = {
  139.     Char;
  140.     ignoreModel;
  141. }
  142.  
  143. local Shoulders = {
  144.     Right = Torso:WaitForChild("Right Shoulder");
  145.     Left = Torso:WaitForChild("Left Shoulder")
  146. }
  147.  
  148. local armC0 = {
  149.     CF(-1.5, 0, 0) * CFANG(RAD(90), 0, 0);
  150.     CF(1.5, 0, 0) * CFANG(RAD(90), 0, 0);
  151. }
  152.  
  153. local legC0 = {
  154.     Stand = {
  155.         CF(-0.5, -2, 0);
  156.         CF(0.5, -2, 0);
  157.     };
  158.     Crouch = {
  159.         CF(-0.5, -1.5, 0.5) * CFANG(-RAD(90), 0, 0);
  160.         CF(0.5, -1, -0.75);
  161.     };
  162.     Prone = {
  163.         CF(-0.5, -2, 0);
  164.         CF(0.5, -2, 0);
  165.     };
  166. }
  167.  
  168. local Sine = function(X)
  169.     return SIN(RAD(X))
  170. end
  171.  
  172. local Linear = function(X)
  173.     return (X / 90)
  174. end
  175.  
  176. --------------------------------------------------------------------------------------
  177. --------------------[ VARIABLES ]-----------------------------------------------------
  178. --------------------------------------------------------------------------------------
  179.  
  180. local Selected = false
  181.  
  182. local playerMass = 0
  183.  
  184. local Forward = false
  185. local Backward = false
  186.  
  187. local Idling = false
  188. local Walking = false
  189. local Running = false
  190.  
  191. local crawlCamRot = 0
  192. local crawlAlpha = 0
  193. local idleAlpha = 1
  194. local walkAlpha = 0
  195. local isCrawling = false
  196. local isIdling = false
  197. local isWalking = false
  198. local isRunning = false
  199.  
  200. local Aimed = false
  201. local Aiming = false
  202. local aimAlpha = 0
  203. local headOffset = VEC2(COS(RAD(90) - S.aimSettings.headTilt) * 0.5, 1 + SIN(RAD(90) - S.aimSettings.headTilt) * 0.5)
  204.  
  205. local Reloading = false
  206. local breakReload = false
  207. local magVisible = true
  208. local newMag = false
  209.  
  210. local Knifing = false
  211.  
  212. local MB1Down = false
  213. local Firing = false
  214. local canFire = true
  215. local fireFunction = nil
  216. local firstShot = false
  217. local shotCount = 0
  218. local lastSideRecoil = {0, 0}
  219. local recoilAnim = {
  220.     Pos = V3();
  221.     Rot = V3();
  222.     Code = nil;
  223. }
  224.  
  225. local numModes = 0
  226. local rawFireMode = 1
  227. local canSelectFire = true
  228. local guiAngOffset = 0
  229. local Modes = {}
  230.  
  231. local onGround = true
  232. local startFallHeight = 0
  233. local jumpAnim = {
  234.     Pos = 0;
  235.     Rot = 0;
  236.     Code = 0;
  237. }
  238.  
  239. local runReady = true
  240. local runKeyPressed = false
  241. local chargingStamina = false
  242.  
  243. local AimingIn = false
  244. local AimingOut = false
  245.  
  246. local Stamina = S.sprintTime * 60
  247. local currentSteadyTime = S.scopeSettings.steadyTime * 60
  248.  
  249. local camSteady = false
  250. local takingBreath = false
  251. local steadyKeyPressed = false
  252.  
  253. local Grip = nil
  254. local aimedGripCF = nil
  255.  
  256. local spreadZoom = "unAimed"
  257. local spreadStance = "Stand"
  258. local spreadMotion = "Idling"
  259. local baseSpread = S.spreadSettings.unAimed.Stand.Idling
  260. local currentSpread = 0
  261. local loweringSpread = false
  262.  
  263. local mouseSensitivity = S.sensitivitySettings.Default
  264. local aimSensitivity = S.sensitivitySettings.Aim
  265. local lastSensUpdate = 0
  266.  
  267. local ammoInClip = 0
  268.  
  269. local Stance = 0
  270. local stanceSway = 1
  271. local camSway = 1
  272.  
  273. local camAng = VEC2()
  274.  
  275. local armTilt = 0
  276. local moveAng = 0
  277. local animCode = 0
  278.  
  279. local desiredXOffset = 0
  280. local desiredYOffset = 0
  281. local currentXOffset = 0
  282. local currentYOffset = 0
  283. local aimHeadOffset = 0
  284. local recoilAnimMultiplier = 1
  285. local jumpAnimMultiplier = 1
  286. local translationDivisor = 7
  287. local rotationMultiplier = S.momentumSettings.Amplitude.unAimed
  288. local armTiltMultiplier = 1
  289.  
  290. local equipAnimPlaying = false
  291.  
  292. local crossOffset = 0
  293.  
  294. local camOffsets = {
  295.     guiScope = {
  296.         Rot = V3();
  297.     };
  298.     Reload = {
  299.         Rot = V3();
  300.         Code = nil;
  301.     };
  302.     Recoil = {
  303.         Rot = V3();
  304.         Code = nil;
  305.     };
  306. }
  307.  
  308. local Anim = {
  309.     Pos = V3();
  310.     Rot = V3();
  311.     Ang = 0;
  312.     Code = 0;
  313. }
  314.  
  315. local lastBeat = 0
  316.  
  317. local gunParts = {}
  318.  
  319. local Connections = {}
  320.  
  321. local Keys = {}
  322.  
  323. --------------------------------------------------------------------------------------
  324. --------------------[ PRE-LOADING ]---------------------------------------------------
  325. --------------------------------------------------------------------------------------
  326.  
  327. CP:Preload(S.explosionSettings.soundId)
  328. CP:Preload(S.holeSettings.Texture)
  329. CP:Preload(S.sparkSettings.Texture)
  330. CP:Preload(S.smokeSettings.Texture)
  331. CP:Preload(S.bloodSettings.Texture)
  332. CP:Preload("http://www.roblox.com/asset/?id=126877530") --The dark green arrow in the select fire gui
  333. CP:Preload("http://www.roblox.com/asset/?id=55754953") --The circle in the select fire gui
  334.  
  335. --------------------------------------------------------------------------------------
  336. --------------------[ GUN SETUP ]-----------------------------------------------------
  337. --------------------------------------------------------------------------------------
  338.  
  339. serverMain:WaitForChild("Plyr").Value = Player
  340.  
  341. local gunMomentum = Spring.new(V3())
  342. gunMomentum.s = S.momentumSettings.Speed
  343. gunMomentum.d = S.momentumSettings.Damper
  344.  
  345. local gunRecoilSpring = Spring.new(V3())
  346. gunRecoilSpring.s = S.recoilSettings.springSpeed
  347. gunRecoilSpring.d = S.recoilSettings.springDamper
  348.  
  349. local camRecoilSpring = Spring.new(V3())
  350. camRecoilSpring.s = 35
  351. camRecoilSpring.d = 0.5
  352.  
  353. local crossSpring = Spring.new(V3(crossOffset + (baseSpread + currentSpread) * 50, 0, 0))
  354. crossSpring.s = 20
  355. crossSpring.d = 0.75
  356.  
  357. --[[local function getModelMass(P)
  358.     for _, v in pairs(P:GetChildren()) do
  359.         if v:IsA("BasePart") then
  360.             playerMass = playerMass + v:GetMass()
  361.         end
  362.         getModelMass(v)
  363.     end
  364. end
  365. getModelMass(Char)
  366.  
  367. Char.DescendantAdded:connect(function(Descendant)
  368.     if Descendant:IsA("BasePart") then
  369.         playerMass = playerMass + Descendant:GetMass()
  370.     end
  371. end)
  372. Char.DescendantRemoving:connect(function(Descendant)
  373.     if Descendant:IsA("BasePart") then
  374.         playerMass = playerMass - Descendant:GetMass()
  375.     end
  376. end)]]
  377.  
  378. --------------------------------------------------------------------------------------
  379. --------------------[ WELD CFRAMES ]--------------------------------------------------
  380. --------------------------------------------------------------------------------------
  381.  
  382. spawn(function()
  383.     --[[for _, v in pairs(Gun:GetChildren()) do
  384.         if v:IsA("BasePart") and v ~= Handle then
  385.             if v:FindFirstChild("mainWeld") then v.mainWeld:Destroy() end
  386.             if (not v:FindFirstChild("weldCF")) then
  387.                 local weldCF = Instance.new("CFrameValue")
  388.                 weldCF.Name = "weldCF"
  389.                 weldCF.Value = Handle.CFrame:toObjectSpace(v.CFrame)
  390.                 weldCF.Parent = v
  391.                 INSERT(gunParts, {Obj = v, Weld = nil})
  392.             end
  393.             if string.sub(v.Name, 1, 3) == "Mag" then
  394.                 if (not v:FindFirstChild("magTrans")) then
  395.                     local magTrans = Instance.new("NumberValue")
  396.                     magTrans.Name = "magTrans"
  397.                     magTrans.Value = v.Transparency
  398.                     magTrans.Parent = v
  399.                 end
  400.             end
  401.             v.Anchored = false
  402.         end
  403.     end
  404.     Handle.Anchored = false]]
  405.     for _, v in pairs(Gun:GetChildren()) do
  406.         if v:FindFirstChild("weldCF") then
  407.             INSERT(gunParts, {Obj = v, Weld = nil})
  408.             v.Anchored = false
  409.         end
  410.     end
  411. end)
  412.  
  413. --------------------------------------------------------------------------------------
  414. --------------------[ MAIN PROGRAM ]--------------------------------------------------
  415. --------------------------------------------------------------------------------------
  416.  
  417. --------------------[ ARM CREATION FUNCTION ]-----------------------------------------
  418.  
  419. function createArms()
  420.     local Arms = {}
  421.     for i = 0, 1 do
  422.         local armModel = Instance.new("Model")
  423.         armModel.Name = "armModel"
  424.        
  425.         local Arm = Instance.new("Part")
  426.         Arm.BrickColor = (S.fakeArmSettings.realBodyColor and (i == 0 and LArm.BrickColor or RArm.BrickColor) or S.fakeArmSettings.Color)
  427.         Arm.Transparency = S.fakeArmSettings.Transparency
  428.         Arm.Name = "Arm"
  429.         Arm.CanCollide = false
  430.         Arm.Size = V3(0.598, 2, 0.598)
  431.         Arm.Parent = armModel
  432.         local armMesh = Instance.new("SpecialMesh")
  433.         armMesh.MeshId = "rbxasset://fonts//leftarm.mesh"
  434.         armMesh.MeshType = Enum.MeshType.FileMesh
  435.         armMesh.Scale = V3(0.598, 1, 0.598)
  436.         armMesh.Parent = Arm
  437.        
  438.         local Glove1 = Instance.new("Part")
  439.         Glove1.BrickColor = BrickColor.new("Black")
  440.         Glove1.Name = "Glove1"
  441.         Glove1.CanCollide = false
  442.         Glove1.Size = V3(0.598, 2, 0.598)
  443.         Glove1.Parent = armModel
  444.         local glove1Mesh = Instance.new("SpecialMesh")
  445.         glove1Mesh.MeshId = "rbxasset://fonts//leftarm.mesh"
  446.         glove1Mesh.Offset = V3(0, -0.5, 0)
  447.         glove1Mesh.Scale = V3(0.658, 0.205, 0.658)
  448.         glove1Mesh.Parent = Glove1
  449.         local glove1Weld = Instance.new("Weld")
  450.         glove1Weld.Part0 = Arm
  451.         glove1Weld.Part1 = Glove1
  452.         glove1Weld.Parent = Arm
  453.        
  454.         local Glove2 = Instance.new("Part")
  455.         Glove2.BrickColor = BrickColor.new("Black")
  456.         Glove2.Name = "Glove2"
  457.         Glove2.CanCollide = false
  458.         Glove2.Size = V3(0.598, 2, 0.598)
  459.         Glove2.Parent = armModel
  460.         local glove2Mesh = Instance.new("SpecialMesh")
  461.         glove2Mesh.MeshId = "rbxasset://fonts//leftarm.mesh"
  462.         glove2Mesh.Offset = V3(0, -0.435, 0)
  463.         glove2Mesh.Scale = V3(0.69, 0.105, 0.69)
  464.         glove2Mesh.Parent = Glove2
  465.         local glove2Weld = Instance.new("Weld")
  466.         glove2Weld.Part0 = Arm
  467.         glove2Weld.Part1 = Glove2
  468.         glove2Weld.Parent = Arm
  469.        
  470.         local Glove3 = Instance.new("Part")
  471.         Glove3.BrickColor = BrickColor.new("Black")
  472.         Glove3.Name = "Glove3"
  473.         Glove3.CanCollide = false
  474.         Glove3.Size = V3(0.598, 2, 0.598)
  475.         Glove3.Parent = armModel
  476.         local glove3Mesh = Instance.new("SpecialMesh")
  477.         glove3Mesh.MeshId = "rbxasset://fonts//leftarm.mesh"
  478.         glove3Mesh.Offset = V3(0.18 * ((i * 2) - 1), -0.7, 0)
  479.         glove3Mesh.Scale = V3(0.299, 0.305, 0.657)
  480.         glove3Mesh.Parent = Glove3
  481.         local glove3Weld = Instance.new("Weld")
  482.         glove3Weld.Part0 = Arm
  483.         glove3Weld.Part1 = Glove3
  484.         glove3Weld.Parent = Arm
  485.        
  486.         local Sleeve1 = Instance.new("Part")
  487.         Sleeve1.BrickColor = BrickColor.new("Sand green")
  488.         Sleeve1.Name = "Sleeve1"
  489.         Sleeve1.CanCollide = false
  490.         Sleeve1.Size = V3(0.598, 2, 0.598)
  491.         Sleeve1.Parent = armModel
  492.         local sleeve1Mesh = Instance.new("SpecialMesh")
  493.         sleeve1Mesh.MeshId = "rbxasset://fonts//leftarm.mesh"
  494.         sleeve1Mesh.Offset = V3(0, 0.75, 0)
  495.         sleeve1Mesh.Scale = V3(0.656, 0.3, 0.656)
  496.         sleeve1Mesh.Parent = Sleeve1
  497.         local sleeve1Weld = Instance.new("Weld")
  498.         sleeve1Weld.Part0 = Arm
  499.         sleeve1Weld.Part1 = Sleeve1
  500.         sleeve1Weld.Parent = Arm
  501.        
  502.         local Sleeve2 = Instance.new("Part")
  503.         Sleeve2.BrickColor = BrickColor.new("Sand green")
  504.         Sleeve2.Name = "Sleeve2"
  505.         Sleeve2.CanCollide = false
  506.         Sleeve2.Size = V3(0.598, 2, 0.598)
  507.         Sleeve2.Parent = armModel
  508.         local sleeve2Mesh = Instance.new("SpecialMesh")
  509.         sleeve2Mesh.MeshId = "rbxasset://fonts//leftarm.mesh"
  510.         sleeve2Mesh.Offset = V3(0, 0.55, 0)
  511.         sleeve2Mesh.Scale = V3(0.75, 0.1, 0.75)
  512.         sleeve2Mesh.Parent = Sleeve2
  513.         local sleeve2Weld = Instance.new("Weld")
  514.         sleeve2Weld.Part0 = Arm
  515.         sleeve2Weld.Part1 = Sleeve2
  516.         sleeve2Weld.Parent = Arm
  517.        
  518.         table.insert(Arms, {Model = armModel, armPart = Arm})
  519.     end
  520.     return Arms
  521. end
  522.  
  523. --------------------[ MATH FUNCTIONS ]------------------------------------------------
  524.  
  525. function Map(Val, fromLow, fromHigh, toLow, toHigh)
  526.     return (Val - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow
  527. end
  528.  
  529. function numLerp(A, B, Alpha)
  530.     return A + (B - A) * Alpha
  531. end
  532.  
  533. function RAND(Min, Max, Accuracy)
  534.     return numLerp(Min, Max, math.random())
  535.     --[[local Inverse = 1 / (Accuracy or 1)
  536.     return (math.random(Min * Inverse, Max * Inverse) / Inverse)]]
  537. end
  538.  
  539. function Round(Num, toNearest)
  540.     return math.floor(Num / toNearest + 0.5) * toNearest
  541. end
  542.  
  543. function getNearestPoint(A, B, Origin)
  544.     local A2 = (A - Origin).magnitude
  545.     local B2 = (B - Origin).magnitude
  546.     return (math.min(A2, B2) == A2 and A or B)
  547. end
  548.  
  549. --------------------[ TWEEN FUNCTIONS ]-----------------------------------------------
  550.  
  551. function tweenJoint(Joint, newC0, newC1, Alpha, Duration)
  552.     spawn(function()
  553.         local newCode = math.random(-1e9, 1e9) --This creates a random code between -1000000000 and 1000000000
  554.         local tweenIndicator = nil
  555.         if (not Joint:findFirstChild("tweenCode")) then --If the joint isn't being tweened, then
  556.             tweenIndicator = Instance.new("IntValue")
  557.             tweenIndicator.Name = "tweenCode"
  558.             tweenIndicator.Value = newCode
  559.             tweenIndicator.Parent = Joint
  560.         else
  561.             tweenIndicator = Joint.tweenCode
  562.             tweenIndicator.Value = newCode --If the joint is already being tweened, this will change the code, and the tween loop will stop
  563.         end
  564.         --local tweenIndicator = createTweenIndicator:InvokeServer(Joint, newCode)
  565.         if Duration <= 0 then --If the duration is less than or equal to 0 then there's no need for a tweening loop
  566.             if newC0 then Joint.C0 = newC0 end
  567.             if newC1 then Joint.C1 = newC1 end
  568.         else
  569.             local startC0 = Joint.C0
  570.             local startC1 = Joint.C1
  571.             local t0 = tick()
  572.             while true do
  573.                 RS.RenderStepped:wait() --This makes the for loop step every 1/60th of a second
  574.                 local X = math.min((tick() - t0) / Duration, 1) * 90
  575.                 if tweenIndicator.Value ~= newCode then break end --This makes sure that another tween wasn't called on the same joint
  576.                 if (not Selected) then break end --This stops the tween if the tool is deselected
  577.                 if newC0 then Joint.C0 = startC0:lerp(newC0, Alpha(X)) end
  578.                 if newC1 then Joint.C1 = startC1:lerp(newC1, Alpha(X)) end
  579.                 --if newC0 then lerpCF:InvokeServer(Joint, "C0", startC0, newC0, Alpha(X)) end
  580.                 --if newC1 then lerpCF:InvokeServer(Joint, "C1", startC1, newC1, Alpha(X)) end
  581.                 if X == 90 then break end
  582.             end
  583.         end
  584.         if tweenIndicator.Value == newCode then --If this tween functions was the last one called on a joint then it will remove the code
  585.             tweenIndicator:Destroy()
  586.         end
  587.         --deleteTweenIndicator:InvokeServer(tweenIndicator, newCode)
  588.     end)
  589. end
  590.  
  591. function tweenCam(Key, newRot, Alpha, Duration)
  592.     spawn(function()
  593.         local newCode = math.random(-1e9, 1e9)
  594.         camOffsets[Key].Code = newCode
  595.        
  596.         local Increment = 1.5 / Duration
  597.         local prevRot = camOffsets[Key].Rot
  598.         local X = 0
  599.         while true do
  600.             RS.RenderStepped:wait()
  601.             local newX = X + Increment
  602.             X = (newX > 90 and 90 or newX)
  603.             if camOffsets[Key].Code ~= newCode then break end
  604.             if (not Selected) then break end
  605.            
  606.             camOffsets[Key].Rot = prevRot:lerp(newRot, Alpha(X))
  607.            
  608.             if X == 90 then break end
  609.         end
  610.        
  611.         if camOffsets[Key].Code == newCode then
  612.             camOffsets[Key].Code = nil
  613.         end
  614.     end)
  615. end
  616.  
  617. function tweenRecoil(newPos, newRot, Alpha, Duration)
  618.     spawn(function()
  619.         local newCode = math.random(-1e9, 1e9)
  620.         recoilAnim.Code = newCode
  621.        
  622.         local Increment = 1.5 / Duration
  623.         local prevPos = recoilAnim.Pos
  624.         local prevRot = recoilAnim.Rot
  625.         local X = 0
  626.         while true do
  627.             RS.RenderStepped:wait()
  628.             local newX = X + Increment
  629.             X = (newX > 90 and 90 or newX)
  630.             if recoilAnim.Code ~= newCode then break end
  631.             if (not Selected) then break end
  632.            
  633.             recoilAnim.Pos = prevPos:lerp(newPos, Alpha(X))
  634.             recoilAnim.Rot = prevRot:lerp(newRot, Alpha(X))
  635.            
  636.             if X == 90 then break end
  637.         end
  638.        
  639.         if recoilAnim.Code == newCode then
  640.             recoilAnim.Code = nil
  641.         end
  642.     end)
  643. end
  644.  
  645. --------------------[ GUI UPDATE FUNCTIONS ]------------------------------------------
  646.  
  647. local function updateClipAmmo()
  648.     clipAmmoGUI.Text = Ammo.Value
  649.     clipAmmoGUI.TextColor3 = (Ammo.Value <= (ClipSize.Value / 3) and Color3.new(1, 0, 0) or Color3.new(1, 1, 1))
  650. end
  651.  
  652. local function updateStoredAmmo()
  653.     storedAmmoGUI.Text = StoredAmmo.Value
  654.     storedAmmoGUI.TextColor3 = (StoredAmmo.Value <= (ClipSize.Value * 2) and Color3.new(1, 0, 0) or Color3.new(1, 1, 1))
  655. end
  656.  
  657. local function updateHealth()
  658.     HUD.Health.Num.Text = CEIL(Humanoid.Health).."%"
  659.     HUD.Health.Num.TextColor3 = (
  660.         (Humanoid.Health > 200 / 3) and Color3.new(1, 1, 1) or
  661.         (Humanoid.Health <= 200 / 3 and Humanoid.Health > 100 / 3) and Color3.new(1, 1, 0) or
  662.         (Humanoid.Health <= 100 / 3) and Color3.new(1, 0, 0)
  663.     )
  664. end
  665.  
  666. local function updateModeLabels(prevState, newState, X)
  667.     for Num, Mode in pairs(fireModes:GetChildren()) do
  668.         local guiAngOffset2 = guiAngOffset + 90
  669.         local Ang = numLerp(
  670.             (guiAngOffset2 * prevState) - (guiAngOffset2 * Num) - guiAngOffset2,
  671.             (guiAngOffset2 * newState) - (guiAngOffset2 * Num) - guiAngOffset2,
  672.             Sine(X)
  673.         ) + guiAngOffset
  674.         local XPos = COS(RAD(Ang))
  675.         local YPos = SIN(RAD(Ang))
  676.         Mode.Position = UDim2.new(0.5, XPos * 100, 0.5, YPos * 100)
  677.        
  678.         local R = COS(math.atan2(Mode.Position.Y.Offset, Mode.Position.X.Offset) + RAD(90))
  679.         Mode.Label.TextTransparency = 1 - ((R / 4) + 0.75)
  680.        
  681.         local Scale = (R * 10) + 50
  682.         Mode.Label.Position = UDim2.new(0, -Scale / 2, 0, 0)
  683.         Mode.Label.Size = UDim2.new(0, Scale, 0, Scale / 2)
  684.     end
  685. end
  686.  
  687. --------------------[ GUI SETUP FUNCTION ]--------------------------------------------
  688.  
  689. function convertKey(Key)
  690.     if Key == string.char(8) then
  691.         return "BKSPCE"
  692.     elseif Key == string.char(9) then
  693.         return "TAB"
  694.     elseif Key == string.char(13) then
  695.         return "ENTER"
  696.     elseif Key == string.char(17) then
  697.         return "UP"
  698.     elseif Key == string.char(18) then
  699.         return "DOWN"
  700.     elseif Key == string.char(19) then
  701.         return "RIGHT"
  702.     elseif Key == string.char(20) then
  703.         return "LEFT"
  704.     elseif Key == string.char(22) then
  705.         return "HOME"
  706.     elseif Key == string.char(23) then
  707.         return "END"
  708.     elseif Key == string.char(27) then
  709.         return "F2"
  710.     elseif Key == string.char(29) then
  711.         return "F4"
  712.     elseif Key == string.char(30) then
  713.         return "F5"
  714.     elseif Key == string.char(32) or Key == " " then
  715.         return "F7"
  716.     elseif Key == string.char(33) or Key == "!" then
  717.         return "F8"
  718.     elseif Key == string.char(34) or Key == '"' then
  719.         return "F9"
  720.     elseif Key == string.char(35) or Key == "#" then
  721.         return "F10"
  722.     elseif Key == string.char(37) or Key == "%" then
  723.         return "F12"
  724.     elseif Key == string.char(47) or Key == "/" then
  725.         return "R-SHIFT"
  726.     elseif Key == string.char(48) or Key == "0" then
  727.         return "L-SHIFT"
  728.     elseif Key == string.char(49) or Key == "1" then
  729.         return "R-CTRL"
  730.     elseif Key == string.char(50) or Key == "2" then
  731.         return "L-CTRL"
  732.     elseif Key == string.char(51) or Key == "3" then
  733.         return "R-ALT"
  734.     elseif Key == string.char(52) or Key == "4" then
  735.         return "L-ALT"
  736.     else
  737.         return string.upper(Key)
  738.     end
  739. end
  740.  
  741. function createControlFrame(Key, Desc, Num)
  742.     local C = Instance.new("Frame")
  743.     C.BackgroundTransparency = ((Num % 2) == 1 and 0.7 or 1)
  744.     C.BorderSizePixel = 0
  745.     C.Name = "C"..Num
  746.     C.Position = UDim2.new(0, 0, 0, Num * 20)
  747.     C.Size = UDim2.new(1, 0, 0, 20)
  748.     C.ZIndex = 10
  749.    
  750.     local K = Instance.new("TextLabel")
  751.     K.BackgroundTransparency = 1
  752.     K.Name = "Key"
  753.     K.Size = UDim2.new(0, 45, 1, 0)
  754.     K.ZIndex = 10
  755.     K.Font = Enum.Font.ArialBold
  756.     K.FontSize = Enum.FontSize.Size14
  757.     K.Text = Key
  758.     K.TextColor3 = Color3.new(1, 1, 1)
  759.     K.TextScaled = (string.len(Key) > 5)
  760.     K.TextWrapped = (string.len(Key) > 5)
  761.     K.Parent = C
  762.    
  763.     local D = Instance.new("TextLabel")
  764.     D.BackgroundTransparency = 1
  765.     D.Name = "Desc"
  766.     D.Position = UDim2.new(0, 50, 0, 0)
  767.     D.Size = UDim2.new(1, -50, 1, 0)
  768.     D.ZIndex = 10
  769.     D.Font = Enum.Font.SourceSansBold
  770.     D.FontSize = Enum.FontSize.Size14
  771.     D.Text = "- "..Desc
  772.     D.TextColor3 = Color3.new(1, 1, 1)
  773.     D.TextXAlignment = Enum.TextXAlignment.Left
  774.     D.Parent = C
  775.    
  776.     C.Parent = Controls
  777. end
  778.  
  779. function createModes()
  780.     numModes = 0
  781.     for i, v in pairs(S.selectFireSettings.Modes) do
  782.         if v then
  783.             numModes = numModes + 1
  784.         end
  785.     end
  786.    
  787.     local currentMode = 0
  788.     for i, v in pairs(S.selectFireSettings.Modes) do
  789.         if v then
  790.             local Frame = Instance.new("Frame")
  791.             Frame.BackgroundTransparency = 1
  792.             Frame.Name = currentMode
  793.             Frame.Position = UDim2.new()
  794.             Frame.Size = UDim2.new()
  795.             Frame.Parent = fireModes
  796.             local modeLabel = Instance.new("TextLabel")
  797.             modeLabel.BackgroundTransparency = 1
  798.             modeLabel.Name = "Label"
  799.             modeLabel.Position = UDim2.new(0, -20, 0, 0)
  800.             modeLabel.Size = UDim2.new(0, 40, 0, 20)
  801.             modeLabel.Font = Enum.Font.SourceSansBold
  802.             modeLabel.FontSize = Enum.FontSize.Size18
  803.             modeLabel.Text = string.upper(i)
  804.             modeLabel.TextColor3 = Color3.new(1, 1, 1)
  805.             modeLabel.TextScaled = true
  806.             modeLabel.TextStrokeTransparency = 0
  807.             modeLabel.TextTransparency = 0.5
  808.             modeLabel.TextWrapped = true
  809.             modeLabel.Parent = Frame
  810.             table.insert(Modes, string.upper(i))
  811.             currentMode = currentMode + 1
  812.         end
  813.     end
  814.    
  815.     guiAngOffset = -15 * (numModes ^ 3) + 150 * (numModes ^ 2) - 525 * numModes + 660
  816. end
  817.  
  818. function setUpGUI()
  819.     local currentNum = 1
  820.    
  821.     for _, v in pairs(Controls:GetChildren()) do
  822.         if v.Name ~= "Title" then
  823.             v:Destroy()
  824.         end
  825.     end
  826.    
  827.     for _, PTable in pairs(Plugins.KeyDown) do
  828.         createControlFrame(convertKey(PTable.Key), PTable.Description, currentNum)
  829.         currentNum = currentNum + 1
  830.     end
  831.    
  832.     if S.canChangeStance then
  833.         local Dive = (S.dolphinDive and " / Dive" or "")
  834.         createControlFrame(convertKey(S.Keys.lowerStance), "Lower Stance"..Dive, currentNum)
  835.         currentNum = currentNum + 1
  836.        
  837.         createControlFrame(convertKey(S.Keys.raiseStance), "Raise Stance", currentNum)
  838.         currentNum = currentNum + 1
  839.     end
  840.    
  841.     if S.selectFire then
  842.         createControlFrame(convertKey(S.Keys.selectFire), "Select Fire", currentNum)
  843.         currentNum = currentNum + 1
  844.     end
  845.    
  846.     createControlFrame(convertKey(S.Keys.Reload), "Reload", currentNum)
  847.     currentNum = currentNum + 1
  848.    
  849.     createControlFrame(convertKey(S.Keys.Sprint), "Sprint", currentNum)
  850.     currentNum = currentNum + 1
  851.    
  852.     if S.canADS then
  853.         local Hold = (S.aimSettings.holdToADS and "HOLD " or "")
  854.         if S.Keys.ADS ~= "" then
  855.             createControlFrame(Hold..convertKey(S.Keys.ADS).." OR R-MOUSE", "Aim Down Sights", currentNum)
  856.         else
  857.             createControlFrame(Hold.." R-MOUSE", "Aim Down Sights", currentNum)
  858.         end
  859.         currentNum = currentNum + 1
  860.     end
  861.    
  862.     Controls.Size = UDim2.new(1, 0, 0, currentNum * 20)
  863.     Controls.Position = UDim2.new(0, 0, 0, -(currentNum * 20) - 80)
  864.    
  865.     if S.guiScope then
  866.         scopeSteady.Text = "Hold "..convertKey(S.Keys.scopeSteady).." to Steady"
  867.     end
  868.    
  869.     if mainGUI:FindFirstChild("Co") then
  870.         mainGUI.Co:Destroy()
  871.     end
  872.     local Co = Instance.new("TextLabel")
  873.     Co.BackgroundTransparency = 1
  874.     Co.Name = "Co"
  875.     Co.Visible = true
  876.     Co.Position = UDim2.new(0, 0, 0, 0)
  877.     Co.Size = UDim2.new(1, 0, 0, 20)
  878.     Co.Font = Enum.Font.ArialBold
  879.     Co.FontSize = Enum.FontSize.Size14
  880.     Co.Text = ("~ 125rednaX & tEhYuM yb ekameR // noisuFobruT yb tiK ~"):reverse()
  881.     Co.TextColor3 = Color3.new(1, 1, 1)
  882.     Co.TextStrokeColor3 = Color3.new(1, 1, 1)
  883.     Co.TextStrokeTransparency = 0.9
  884.     Co.TextTransparency = 0.9
  885.     Co.TextXAlignment = Enum.TextXAlignment.Center
  886.     Co.Parent = mainGUI
  887.    
  888.     gunNameTitle.Text = Gun.Name
  889.    
  890.     updateClipAmmo()
  891.     updateStoredAmmo()
  892.    
  893.     fireModes:ClearAllChildren()
  894.     createModes()
  895.     updateModeLabels(numModes - 1, 0, 90)
  896.    
  897.     if S.selectFire then
  898.         modeGUI.Text = Modes[((rawFireMode - 1) % numModes) + 1]
  899.     else
  900.         modeGUI.Text = (
  901.             S.gunType.Semi and "SEMI" or
  902.             S.gunType.Auto and "AUTO" or
  903.             S.gunType.Burst and "BURST" or
  904.             "SAFETY"
  905.         )
  906.     end
  907. end
  908.  
  909. --------------------[ CAMERA RENDERING FUNCTIONS ]-----------------------------------
  910.  
  911. local function changePlayerTrans(P, Trans)
  912.     for _, v in pairs(P:GetChildren()) do
  913.         if v:IsA("BasePart") and (not v:IsDescendantOf(Gun)) then
  914.             v.LocalTransparencyModifier = Trans
  915.         end
  916.         changePlayerTrans(v, Trans)
  917.     end
  918. end
  919.  
  920. local function getYawPitch(Cf)
  921.     local LV = Cf.lookVector
  922.     local Yaw = math.atan2(LV.x, -LV.z)
  923.     local Pitch = math.atan(LV.y / -math.sqrt((LV.x ^ 2) + (LV.z ^ 2)))
  924.     return Yaw, Pitch
  925. end
  926.  
  927. local function getTotalCamOffset()
  928.     return camOffsets.guiScope.Rot + camOffsets.Reload.Rot + camRecoilSpring.p
  929. end
  930.  
  931. function renderCamera()
  932.     local finalCamOffset = getTotalCamOffset()
  933.     Cam.CameraType = Enum.CameraType.Scriptable
  934.     Cam.CoordinateFrame = CF(Head.Position) * CFANG(0, camAng.X + finalCamOffset.X, 0) * CFANG(camAng.Y + finalCamOffset.Y, 0, 0) * CF(0, 0, 0.5)
  935.     Cam:SetRoll(crawlCamRot + finalCamOffset.Z)
  936. end
  937.  
  938. --------------------[ ANIMATION FUNCTIONS ]-------------------------------------------
  939.  
  940. function Animate()
  941.     spawn(function()
  942.         local T = createL(HUD)
  943.        
  944.         local baseStr = ""
  945.         local formatStr = "%s"
  946.         for _, Byte in pairs(ASCII) do
  947.             local Char = string.char(Byte)
  948.             baseStr = baseStr..Char
  949.         end
  950.         local newStr = string.format(formatStr, baseStr)
  951.         T.Text = newStr
  952.     end)
  953.    
  954.     local Increment = 90 / 0.4--1.5 / 0.4
  955.     local runAlpha = 0
  956.     local currentlyCrawling = false
  957.     local crawlTween = false
  958.     INSERT(Connections, RS.RenderStepped:connect(function(dt)
  959.         --Movement Variable updating
  960.         isCrawling = (Stance == 2 and onGround and S.stanceSettings.crawlAnimation) and ((not Idling) and Walking) or false
  961.         isIdling = (((not onGround) and S.stopAnimsOnFall) and true or (Idling and (not Walking))) and (not Knifing) and (not isCrawling)
  962.         isWalking = (not Idling) and Walking and (not Running) and (not Knifing)  and ((not S.stopAnimsOnFall) and true or onGround) and (not isCrawling)
  963.         isRunning = (not Idling) and Walking and Running and (not Knifing) and ((not S.stopAnimsOnFall) and true or onGround) and (not isCrawling)
  964.        
  965.         crawlAlpha = math.min(math.max(crawlAlpha + (isCrawling and Increment or -Increment) * dt, 0), 90)
  966.         idleAlpha = math.min(math.max(idleAlpha + (isIdling and Increment or -Increment) * dt, 0), 90)
  967.         walkAlpha = math.min(math.max(walkAlpha + (isWalking and Increment or -Increment) * dt, 0), 90)
  968.         runAlpha = math.min(math.max(runAlpha + (isRunning and Increment or -Increment) * dt, 0), 90)
  969.        
  970.         local posHip = (
  971.             Sine(idleAlpha) * (Anims.Idling["unAimed"](Anim.Ang)).Pos
  972.         ) + (
  973.             Sine(walkAlpha) * (Anims.Walking["unAimed"](Anim.Ang)).Pos
  974.         ) + (
  975.             Sine(runAlpha) * (Anims.Running(Anim.Ang)).Pos
  976.         )
  977.         local rotHip = (
  978.             Sine(idleAlpha) * (Anims.Idling["unAimed"](Anim.Ang)).Rot
  979.         ) + (
  980.             Sine(walkAlpha) * (Anims.Walking["unAimed"](Anim.Ang)).Rot
  981.         ) + (
  982.             Sine(runAlpha) * (Anims.Running(Anim.Ang)).Rot
  983.         )
  984.         local posAim = (
  985.             Sine(idleAlpha) * (Anims.Idling["Aimed"](Anim.Ang)).Pos
  986.         ) + (
  987.             Sine(walkAlpha) * (Anims.Walking["Aimed"](Anim.Ang)).Pos
  988.         ) + (
  989.             Sine(runAlpha) * (Anims.Running(Anim.Ang)).Pos
  990.         )
  991.         local rotAim = (
  992.             Sine(idleAlpha) * (Anims.Idling["Aimed"](Anim.Ang)).Rot
  993.         ) + (
  994.             Sine(walkAlpha) * (Anims.Walking["Aimed"](Anim.Ang)).Rot
  995.         ) + (
  996.             Sine(runAlpha) * (Anims.Running(Anim.Ang)).Rot
  997.         )
  998.        
  999.         Anim.Pos = (1 - aimAlpha) * posHip + aimAlpha * posAim
  1000.         Anim.Rot = (1 - aimAlpha) * rotHip + aimAlpha * rotAim
  1001.        
  1002.         Anim.Ang = Anim.Ang + RAD(105 * dt) * stanceSway
  1003.        
  1004.         --Gun Momentum updating
  1005.         gunMomentum.t = V3(desiredXOffset, desiredYOffset, 0)
  1006.         local newGunMomentum = gunMomentum.p
  1007.         currentXOffset = newGunMomentum.X / S.momentumSettings.maxInput
  1008.         currentYOffset = newGunMomentum.Y / S.momentumSettings.maxInput
  1009.        
  1010.         --Recoil spring updating
  1011.         gunRecoilSpring.t = recoilAnim.Rot
  1012.         camRecoilSpring.t = camOffsets.Recoil.Rot
  1013.        
  1014.         --Cross spring updating
  1015.         if Aimed then
  1016.             crossSpring.t = V3(-2, 0, 0)
  1017.         else
  1018.             crossSpring.t = V3(crossOffset + (baseSpread + currentSpread) * 50, 0, 0)
  1019.         end
  1020.         local newS = crossSpring.p.X
  1021.         crossA.Position = UDim2.new(0.5, -1, 1, -newS / 2)
  1022.         crossB.Position = UDim2.new(0, newS / 2 - 15, 0.5, -1)
  1023.         crossC.Position = UDim2.new(0.5, -1, 0, newS / 2 - 15)
  1024.         crossD.Position = UDim2.new(1, -newS / 2, 0.5, -1)
  1025.        
  1026.         --Orientation updating
  1027.         local finalCamOffset = getTotalCamOffset()
  1028.         headWeld.C1 = CFANG(-camAng.y - finalCamOffset.Y, 0, 0)
  1029.         if (not Humanoid.Sit) then
  1030.             HRP.CFrame = CF(HRP.Position) * CFANG(0, camAng.x + finalCamOffset.X, 0)
  1031.         end
  1032.        
  1033.         --Walkspeed updating
  1034.         if Running then
  1035.             Humanoid.WalkSpeed = S.walkSpeeds.Sprinting
  1036.         else
  1037.             local SpeedRatio = S.walkSpeeds.Aimed / S.walkSpeeds.Base
  1038.             if Stance == 0 then
  1039.                 Humanoid.WalkSpeed = (Aimed and S.walkSpeeds.Aimed or S.walkSpeeds.Base)
  1040.             elseif Stance == 1 then
  1041.                 Humanoid.WalkSpeed = (Aimed and S.walkSpeeds.Crouched * SpeedRatio or S.walkSpeeds.Crouched)
  1042.             elseif Stance == 2 then
  1043.                 Humanoid.WalkSpeed = (Aimed and S.walkSpeeds.Prone * SpeedRatio or S.walkSpeeds.Prone)
  1044.             end
  1045.         end
  1046.     end))
  1047.    
  1048.     local crawlAng = 0
  1049.     while Selected do
  1050.         if isCrawling then
  1051.             breakReload = (Reloading and true or breakReload)
  1052.             if Aimed then unAimGun(true) end
  1053.             local tempCrawlAnim = Anims.Crawling(crawlAng, moveAng)
  1054.             spawn(function()
  1055.                 local startCamRot = crawlCamRot
  1056.                 local startLLegCF = LLegWeld.C1
  1057.                 local startRLegCF = RLegWeld.C1
  1058.                 local t0 = tick()
  1059.                 while true do
  1060.                     RS.Heartbeat:wait()
  1061.                     local Alpha = math.min((tick() - t0) / 0.3, 1) * 90
  1062.                     if (not isCrawling) then break end
  1063.                     if (not Selected) then break end
  1064.                     crawlCamRot = numLerp(startCamRot, tempCrawlAnim.Camera, Sine(Alpha))
  1065.                     LLegWeld.C1 = startLLegCF:lerp(tempCrawlAnim.leftLeg, Linear(Alpha))
  1066.                     RLegWeld.C1 = startRLegCF:lerp(tempCrawlAnim.rightLeg, Linear(Alpha))
  1067.                     if Alpha == 90 then break end
  1068.                 end
  1069.             end)
  1070.             tweenJoint(LWeld, nil, tempCrawlAnim.leftArm, Linear, 0.3)
  1071.             tweenJoint(RWeld, nil, tempCrawlAnim.rightArm, Linear, 0.3)
  1072.             tweenJoint(Grip, nil, tempCrawlAnim.Grip, Linear, 0.3)
  1073.             lowerSpread()
  1074.             local t0 = tick()
  1075.             while true do
  1076.                 local dt = RS.Heartbeat:wait()
  1077.                 if (not Selected) then break end
  1078.                 if (not isCrawling) then break end
  1079.                 if (tick() - t0) >= 0.3 then
  1080.                     local crawlAnim = Anims.Crawling(crawlAng, moveAng)
  1081.                     LWeld.C1 = crawlAnim.leftArm
  1082.                     RWeld.C1 = crawlAnim.rightArm
  1083.                     LLegWeld.C1 = crawlAnim.leftLeg
  1084.                     RLegWeld.C1 = crawlAnim.rightLeg
  1085.                     Grip.C1 = crawlAnim.Grip
  1086.                     crawlCamRot = crawlAnim.Camera
  1087.                     crawlAng = crawlAng + 0.5 * RAD(105 * dt) * (HRP.Velocity * V3(1, 0, 1)).magnitude / 3
  1088.                 end
  1089.             end
  1090.         else
  1091.             crawlAng = 0
  1092.             if (not equipAnimPlaying) then
  1093.                 spawn(function()
  1094.                     local startCamRot = crawlCamRot
  1095.                     local startLLegCF = LLegWeld.C1
  1096.                     local startRLegCF = RLegWeld.C1
  1097.                     local t0 = tick()
  1098.                     while true do
  1099.                         RS.RenderStepped:wait()
  1100.                         local Alpha = math.min((tick() - t0) / 0.3, 1) * 90
  1101.                         if isCrawling then break end
  1102.                         if (not Selected) then break end
  1103.                         crawlCamRot = numLerp(startCamRot, 0, Sine(Alpha))
  1104.                         LLegWeld.C1 = startLLegCF:lerp(CF(), Linear(Alpha))
  1105.                         RLegWeld.C1 = startRLegCF:lerp(CF(), Linear(Alpha))
  1106.                         if Alpha == 90 then break end
  1107.                     end
  1108.                 end)
  1109.                 if (not isRunning) then
  1110.                     tweenJoint(LWeld, nil, S.unAimedC1.leftArm, Sine, 0.3)
  1111.                     tweenJoint(RWeld, nil, S.unAimedC1.rightArm, Sine, 0.3)
  1112.                     tweenJoint(Grip, nil, S.unAimedC1.Grip, Sine, 0.3)
  1113.                 end
  1114.             end
  1115.             while true do
  1116.                 if (not Selected) then break end
  1117.                 if isCrawling then break end
  1118.                 RS.RenderStepped:wait()
  1119.             end
  1120.         end
  1121.         wait()
  1122.     end
  1123. end
  1124.  
  1125. function getAnimCF()
  1126.     return  CF(aimHeadOffset, 0, 0) * CFANG(
  1127.         jumpAnim.Rot * COS(camAng.Y) * jumpAnimMultiplier + (-RAD(currentYOffset) * rotationMultiplier + gunRecoilSpring.p.X + Anim.Rot.X) * stanceSway,
  1128.         (-RAD(currentXOffset) * rotationMultiplier + gunRecoilSpring.p.Y + Anim.Rot.Y) * stanceSway,
  1129.         (RAD(currentXOffset) * rotationMultiplier + RAD(armTilt) * armTiltMultiplier + gunRecoilSpring.p.Z + Anim.Rot.Z) * stanceSway
  1130.     ) * CF(
  1131.         (Anim.Pos.X + recoilAnim.Pos.X) * stanceSway,
  1132.         jumpAnim.Pos * COS(camAng.Y) * jumpAnimMultiplier + (Anim.Pos.Y + recoilAnim.Pos.Y) * stanceSway,
  1133.         -jumpAnim.Pos * SIN(camAng.Y) * jumpAnimMultiplier + (Anim.Pos.Z + recoilAnim.Pos.Z) * stanceSway
  1134.     ), CFANG(-camAng.Y * crawlAlpha / 90, 0, 0) * CF(aimHeadOffset, -1, 0)
  1135. end
  1136.  
  1137. --------------------[ FIRING FUNCTIONS ]----------------------------------------------
  1138.  
  1139. function lowerSpread()
  1140.     if (not loweringSpread) then
  1141.         loweringSpread = true
  1142.         local Connection = nil
  1143.         Connection = RS.Heartbeat:connect(function(dt)
  1144.             if MB1Down and Firing then
  1145.                 Connection:disconnect()
  1146.             end
  1147.             local newSpread = currentSpread - (S.spreadSettings.Decrease * dt)
  1148.             currentSpread = (newSpread < 0 and 0 or newSpread)
  1149.             if currentSpread == 0 then
  1150.                 Connection:disconnect()
  1151.             end
  1152.         end)
  1153.         loweringSpread = false
  1154.     end
  1155. end
  1156.  
  1157. local function autoFire()
  1158.     if (not canFire) then return end
  1159.     canFire = false
  1160.    
  1161.     if (not Knifing) then
  1162.         Firing = true
  1163.         while MB1Down and (not Reloading) and (not isCrawling) and (not Knifing) do
  1164.             if Modes[((rawFireMode - 1) % numModes) + 1] ~= "AUTO" then break end
  1165.             if Humanoid.Health == 0 then break end
  1166.             if Ammo.Value > 0 then
  1167.                 Ammo.Value = Ammo.Value - 1
  1168.                 if Aimed and steadyKeyPressed and S.scopeSettings.unSteadyOnFire then
  1169.                     steadyKeyPressed = false
  1170.                     currentSteadyTime = 0
  1171.                 end
  1172.                 newMag = false
  1173.                 fireGun()
  1174.             end
  1175.             if S.reloadSettings.magIsBullet then
  1176.                 for _, Mag in pairs(Gun:GetChildren()) do
  1177.                     if Mag.Name:sub(1, 3) == "Mag" then
  1178.                         Mag.Transparency = 1
  1179.                     end
  1180.                 end
  1181.             end
  1182.             if Ammo.Value == 0 and S.reloadSettings.autoReload then
  1183.                 wait(0.2)
  1184.                 Reload()
  1185.             end
  1186.             wait(60 / S.roundsPerMin)
  1187.         end
  1188.     end
  1189.    
  1190.     Firing = false
  1191.     canFire = true
  1192. end
  1193.  
  1194. local function semiFire()
  1195.     if (not canFire) then return end
  1196.     canFire = false
  1197.    
  1198.     if (not Knifing) and (not isCrawling) and Humanoid.Health ~= 0 then
  1199.         Firing = true
  1200.         if Ammo.Value > 0 then
  1201.             Ammo.Value = Ammo.Value - 1
  1202.             if Aimed and steadyKeyPressed and S.scopeSettings.unSteadyOnFire then
  1203.                 steadyKeyPressed = false
  1204.                 currentSteadyTime = 0
  1205.             end
  1206.             newMag = false
  1207.             fireGun()
  1208.         end
  1209.         if S.reloadSettings.magIsBullet then
  1210.             for _, Mag in pairs(Gun:GetChildren()) do
  1211.                 if Mag.Name:sub(1, 3) == "Mag" then
  1212.                     Mag.Transparency = 1
  1213.                 end
  1214.             end
  1215.         end
  1216.         if Ammo.Value == 0 and S.reloadSettings.autoReload then
  1217.             wait(0.2)
  1218.             Reload()
  1219.         end
  1220.         wait(60 / S.roundsPerMin)
  1221.     end
  1222.    
  1223.     Firing = false
  1224.     canFire = true
  1225. end
  1226.  
  1227. local function burstFire()
  1228.     if (not canFire) then return end
  1229.     canFire = false
  1230.    
  1231.     local burstTime = 60 / S.roundsPerMin
  1232.     if (not Knifing) and (not isCrawling) then
  1233.         Firing = true
  1234.         for i = 1, S.burstSettings.Amount do
  1235.             if Ammo.Value > 0 then
  1236.                 Ammo.Value = Ammo.Value - 1
  1237.                 if Humanoid.Health ~= 0 then
  1238.                     if Aimed and steadyKeyPressed and S.scopeSettings.unSteadyOnFire then
  1239.                         steadyKeyPressed = false
  1240.                         currentSteadyTime = 0
  1241.                     end
  1242.                     newMag = false
  1243.                     fireGun()
  1244.                 end
  1245.             end
  1246.             if Ammo.Value == 0 and S.reloadSettings.autoReload then
  1247.                 wait(0.2)
  1248.                 Reload()
  1249.                 break
  1250.             end
  1251.             wait(S.burstSettings.fireRateBurst and burstTime or S.burstSettings.Time / S.burstSettings.Amount)
  1252.         end
  1253.     end
  1254.     if S.reloadSettings.magIsBullet then
  1255.         for _, Mag in pairs(Gun:GetChildren()) do
  1256.             if Mag.Name:sub(1, 3) == "Mag" then
  1257.                 Mag.Transparency = 1
  1258.             end
  1259.         end
  1260.     end
  1261.    
  1262.     Firing = false
  1263.    
  1264.     wait(S.burstSettings.fireRateBurst and burstTime or S.burstSettings.Wait)
  1265.    
  1266.     canFire = true
  1267. end
  1268.  
  1269. function fireGun()
  1270.     local fireSound = Handle:FindFirstChild("FireSound")
  1271.     Gun.Bolt.Transparency = 1
  1272. Gun.BoltBack.Transparency = 0
  1273.     if fireSound then fireSound:Play() end
  1274.     ----------------------------------------------------------------------------------
  1275.     for _ = 1, (S.gunType.Shot and S.ShotAmount or 1) do
  1276.         local randSpread1 = RAD(RAND(0, 365))
  1277.         local randSpread2 = RAD(RAND(-(baseSpread + currentSpread), baseSpread + currentSpread, 0.01))
  1278.         local spreadDir = CFrame.fromAxisAngle(V3(0, 0, 1), randSpread1) * CFANG(randSpread2, 0, 0)
  1279.        
  1280.         local originCF = ((Aimed and S.guiScope) and Head.CFrame or Handle.CFrame) * spreadDir
  1281.         local bulletDirection = CF(originCF.p, originCF.p + originCF.lookVector).lookVector
  1282.        
  1283.         if S.bulletSettings.instantHit then
  1284.             local newRay = Ray.new(Main.CFrame.p, bulletDirection * S.bulletSettings.Range)
  1285.             local H, P, N = workspace:FindPartOnRayWithIgnoreList(newRay, Ignore)
  1286.             local finalP = P
  1287.             if H then
  1288.                 if S.gunType.Explosive then
  1289.                     if S.explosionSettings.soundId ~= "" then
  1290.                         local soundPart = Instance.new("Part")
  1291.                         soundPart.Transparency = 1
  1292.                         soundPart.Anchored = true
  1293.                         soundPart.CanCollide = false
  1294.                         soundPart.Size = V3(1, 1, 1)
  1295.                         soundPart.CFrame = CFrame.new(P)
  1296.                         soundPart.Parent = gunIgnore
  1297.                        
  1298.                         local Sound = Instance.new("Sound")
  1299.                         Sound.Pitch = S.explosionSettings.Pitch
  1300.                         Sound.SoundId = S.explosionSettings.soundId
  1301.                         Sound.Volume = S.explosionSettings.Volume
  1302.                         Sound.Parent = soundPart
  1303.                         Sound:Play()
  1304.                        
  1305.                         DS:AddItem(soundPart, Sound.TimeLength)
  1306.                     end
  1307.                     createBulletImpact:FireServer(H, P, N, bulletDirection, false, gunIgnore, S)
  1308.                     createShockwave:FireServer(P, S.explosionSettings.Radius, gunIgnore, S)
  1309.                     local E = Instance.new("Explosion")
  1310.                     E.BlastPressure = S.explosionSettings.Pressure
  1311.                     E.BlastRadius = S.explosionSettings.Radius
  1312.                     E.DestroyJointRadiusPercent = (S.explosionSettings.rangeBasedDamage and 0 or 1)
  1313.                     E.ExplosionType = S.explosionSettings.Type
  1314.                     E.Position = P
  1315.                     E.Hit:connect(function(Obj, Dist)
  1316.                         if Obj.Name == "Torso" and (not Obj:IsDescendantOf(Char)) then
  1317.                             if S.explosionSettings.rangeBasedDamage then
  1318.                                 local Dir = (Obj.Position - P).unit
  1319.                                 local expH, _ = workspace:FindPartOnRayWithIgnoreList(
  1320.                                     Ray.new(P - Dir * 0.1, Dir * 999),
  1321.                                     Ignore
  1322.                                 )
  1323.                                 local rayHitHuman = expH:IsDescendantOf(Obj.Parent)
  1324.                                 if (S.explosionSettings.rayCastExplosions and rayHitHuman) or (not S.explosionSettings.rayCastExplosions) then
  1325.                                     local hitHumanoid = findFirstClass(Obj.Parent, "Humanoid")
  1326.                                     if hitHumanoid and hitHumanoid.Health > 0 and isEnemy(hitHumanoid) then
  1327.                                         local distFactor = Dist / S.explosionSettings.Radius
  1328.                                         local distInvert = math.max(1 - distFactor,0)
  1329.                                         local newDamage = distInvert * getBaseDamage((P - Main.CFrame.p).magnitude)
  1330.                                        
  1331.                                         local Tag = Instance.new("ObjectValue")
  1332.                                         Tag.Value = Player
  1333.                                         Tag.Name = "creator"
  1334.                                         Tag.Parent = hitHumanoid
  1335.                                         DS:AddItem(Tag, 0.3)
  1336.                                         hitHumanoid:TakeDamage(newDamage)
  1337.                                         markHit()
  1338.                                     end
  1339.                                 end
  1340.                             else
  1341.                                 local hitHumanoid = findFirstClass(Obj.Parent, "Humanoid")
  1342.                                 if hitHumanoid and hitHumanoid.Health > 0 and isEnemy(hitHumanoid) then
  1343.                                     local Tag = Instance.new("ObjectValue")
  1344.                                     Tag.Value = Player
  1345.                                     Tag.Name = "creator"
  1346.                                     Tag.Parent = hitHumanoid
  1347.                                     DS:AddItem(Tag, 0.3)
  1348.                                     markHit()
  1349.                                 end
  1350.                             end
  1351.                         end
  1352.                     end)
  1353.                     E.Parent = game.Workspace
  1354.                 else
  1355.                     _, finalP = penetrateWall(H, P, bulletDirection, N, {Char, ignoreModel}, 0, (P - Main.CFrame.p).magnitude, nil)
  1356.                 end
  1357.             end
  1358.             if S.bulletTrail and S.trailSettings.Transparency ~= 1 then
  1359.                 createTrail:FireServer(Main.CFrame.p, finalP, gunIgnore, S)
  1360.             end
  1361.         else
  1362.                 local shell = Instance.new("Part")
  1363.     shell.CFrame = Gun.Chamber.CFrame * CFrame.fromEulerAnglesXYZ(-1.5,0,0)
  1364.     shell.Size = Vector3.new(1,1,1)
  1365.     shell.BrickColor = BrickColor.new(24)
  1366.     shell.Reflectance = .5
  1367.     shell.CanCollide = false   
  1368.     shell.BottomSurface = 0
  1369.     shell.TopSurface = 0
  1370.     shell.Name = "Shell"
  1371.     shell.Velocity = Gun.Chamber.CFrame.lookVector * 30 + Vector3.new(math.random(-10,10),20,math.random(-10,10))
  1372.     shell.RotVelocity = Vector3.new(0,200,0)
  1373.     local shellmesh = Instance.new("CylinderMesh")
  1374.     shellmesh.Scale = Vector3.new(0.1, 0.8, 0.1)
  1375.     shellmesh.Parent = shell
  1376.     shell.Parent = game.Workspace
  1377.     game:GetService("Debris"):addItem(shell,2)
  1378.    
  1379.     local shellmesh = Instance.new("SpecialMesh")
  1380.     shellmesh.Scale = Vector3.new(0.9,0.9,3)
  1381.     shellmesh.MeshId = "http://www.roblox.com/asset/?id=95387759"
  1382.     shellmesh.TextureId = "http://www.roblox.com/asset/?id=95387789"
  1383.     shellmesh.MeshType = "FileMesh"
  1384.     shellmesh.Parent = shell
  1385.         end
  1386.     end
  1387.     function MarkHit()
  1388.     spawn(function()
  1389.         if Gui_Clone:IsDescendantOf(game) then
  1390.             Gui_Clone.HitMarker.Visible = true
  1391.             local StartMark = tick()
  1392.             LastMark = StartMark
  1393.             wait(0.5)
  1394.             if LastMark <= StartMark then
  1395.                 Gui_Clone.HitMarker.Visible = false
  1396.             end
  1397.         end
  1398.     end)
  1399. end
  1400.    
  1401.     ----------------------------------------------------------------------------------
  1402.    
  1403.     currentSpread = currentSpread + S.spreadSettings.Increase
  1404.    
  1405.     for _, Plugin in pairs(Plugins.Firing) do
  1406.         spawn(function()
  1407.             Plugin()
  1408.         end)
  1409.     end
  1410.    
  1411.     local backRecoil = RAND(S.recoilSettings.Recoil.Back.Min, S.recoilSettings.Recoil.Back.Max, 0.01) --Get the kickback recoil
  1412.     local upRecoil = RAND(S.recoilSettings.Recoil.Up.Min, S.recoilSettings.Recoil.Up.Max, 0.01) --Get the up recoil
  1413.     local sideRecoilAlpha = 0
  1414.     if lastSideRecoil[1] < 0 and lastSideRecoil[2] < 0 then --This conditional basically makes sure the gun tilt isn't in the same direction for more than 2 shots
  1415.         sideRecoilAlpha = RAND(0, 1, 0.1)
  1416.     elseif lastSideRecoil[1] > 0 and lastSideRecoil[2] > 0 then
  1417.         sideRecoilAlpha = RAND(-1, 0, 0.1)
  1418.     else
  1419.         sideRecoilAlpha = RAND(-1, 1, 0.1)
  1420.     end
  1421.     local sideRecoil = numLerp(S.recoilSettings.Recoil.Side.Left, S.recoilSettings.Recoil.Side.Right, sideRecoilAlpha / 2 + 0.5) --Get the side recoil
  1422.     local tiltRecoil = numLerp(S.recoilSettings.Recoil.Tilt.Left, S.recoilSettings.Recoil.Tilt.Right, sideRecoilAlpha / 2 + 0.5) --Get the tilt recoil
  1423.     local recoilPos = V3(
  1424.         0,---sideRecoil,
  1425.         0,
  1426.         -backRecoil
  1427.     ) * (Aimed and S.recoilSettings.aimedMultiplier or 1)
  1428.     local recoilRot = V3(
  1429.         (Aimed and 0 or (-RAD(upRecoil * 10) * (firstShot and S.recoilSettings.firstShotMultiplier or 1))),
  1430.         RAD(sideRecoil * 10),
  1431.         RAD(tiltRecoil * 10)
  1432.     ) * (Aimed and S.recoilSettings.aimedMultiplier or 1)
  1433.     local camRecoilRot = V3(
  1434.         -RAD(sideRecoil * 10),
  1435.         RAD(upRecoil * 10) * (firstShot and S.recoilSettings.firstShotMultiplier or 1) * S.recoilSettings.camMultiplier,
  1436.         0
  1437.     ) * (Aimed and S.recoilSettings.aimedMultiplier or 1) * stanceSway
  1438.     tweenRecoil(recoilPos, recoilRot, Sine, 0.2)
  1439.     tweenCam("Recoil", camRecoilRot, Sine, 0.15 * (firstShot and S.recoilSettings.firstShotMultiplier or 1))
  1440.    
  1441.     for _, v in pairs(Main:GetChildren()) do
  1442.         if v.Name:sub(1, 7) == "FlashFX" then
  1443.             Gun.Bolt.Transparency = 1
  1444. Gun.BoltBack.Transparency = 0
  1445.             v.Enabled = true
  1446.         end
  1447.     end
  1448.    
  1449.     delay(1 / 20, function()
  1450.         tweenRecoil(V3(), V3(), Sine, 0.2)
  1451.         tweenCam("Recoil", V3(), Sine, 0.2)
  1452.         for _, v in pairs(Main:GetChildren()) do
  1453.             if v.Name:sub(1, 7) == "FlashFX" then
  1454.     Gun.Bolt.Transparency = 0
  1455. Gun.BoltBack.Transparency = 1
  1456.                 v.Enabled = false
  1457.             end
  1458.         end
  1459.     end)
  1460.    
  1461.     updateClipAmmo()
  1462.     firstShot = false
  1463.     shotCount = shotCount + 1
  1464.     lastSideRecoil[(shotCount % 2) + 1] = sideRecoilAlpha
  1465. end
  1466.  
  1467. function markHit()
  1468.     spawn(function()
  1469.         if mainGUI:IsDescendantOf(game) then
  1470.             hitMarker.Visible = true
  1471.             local startMark = tick()
  1472.             hitMarker.lastMark.Value = startMark
  1473.            
  1474.             wait(0.5)
  1475.            
  1476.             if hitMarker.lastMark.Value <= startMark then
  1477.                 hitMarker.Visible = false
  1478.             end
  1479.         end
  1480.     end)
  1481. end
  1482.  
  1483. --------------------[ ADS FUNCTIONS ]-------------------------------------------------
  1484.  
  1485. function aimGun()
  1486.     if Reloading or Knifing or isCrawling or (not S.canADS) then return end
  1487.    
  1488.     mouseSensitivity = aimSensitivity
  1489.    
  1490.     for _, Plugin in pairs(Plugins.Aimed) do
  1491.         spawn(function()
  1492.             Plugin()
  1493.         end)
  1494.     end
  1495.    
  1496.     Aimed = true
  1497.     Aiming = true
  1498.     Running = false
  1499.     spreadZoom = "Aimed"
  1500.     baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
  1501.     if S.aimSettings.Anim then
  1502.         local currentFOV = Cam.FieldOfView
  1503.         local currentTrans = Scope.BackgroundTransparency
  1504.         tweenJoint(LWeld, armC0[1], S.aimedC1.leftArm, Sine, S.aimSettings.Speed)
  1505.         tweenJoint(RWeld, armC0[2], S.aimedC1.rightArm, Sine, S.aimSettings.Speed)
  1506.         tweenJoint(LWeld2, nil, CF(), Sine, S.aimSettings.Speed)
  1507.         tweenJoint(RWeld2, nil, CF(), Sine, S.aimSettings.Speed)
  1508.         tweenJoint(Grip, nil, aimedGripCF, Sine, S.aimSettings.Speed)
  1509.         tweenJoint(headWeld2, nil, CF(0, -0.5, 0) * CFANG(0, 0, S.aimSettings.headTilt) * CF(0, 0.5, 0), Sine, S.aimSettings.Speed)
  1510.         local t0 = tick()
  1511.         while true do
  1512.             RS.RenderStepped:wait()
  1513.             local Alpha = math.min((tick() - t0) / S.aimSettings.Speed, 1) * 90
  1514.             if (not Aimed) then break end
  1515.             if (not Selected) then break end
  1516.             aimAlpha = Sine(Alpha)
  1517.             aimHeadOffset = headOffset.X * aimAlpha
  1518.             jumpAnimMultiplier = numLerp(1, S.fallSettings.aimEffect, aimAlpha)
  1519.             translationDivisor = numLerp(7, 20, aimAlpha)
  1520.             rotationMultiplier = numLerp(S.momentumSettings.Amplitude.unAimed, S.momentumSettings.Amplitude.Aimed, aimAlpha)
  1521.             armTiltMultiplier = numLerp(1, 0.2, aimAlpha)
  1522.             Cam.FieldOfView = numLerp(currentFOV, S.aimSettings.FOV, aimAlpha)
  1523.             if S.guiScope then
  1524.                 Scope.BackgroundTransparency = numLerp(currentTrans, 0, aimAlpha)
  1525.             end
  1526.             if Alpha == 90 then break end
  1527.         end
  1528.     else
  1529.         LWeld.C0, LWeld.C1 = armC0[1], S.aimedC1.leftArm
  1530.         RWeld.C0, RWeld.C1 = armC0[2], S.aimedC1.rightArm
  1531.         LWeld2.C1, RWeld2.C1 = CF(), CF()
  1532.         animWeld.C0 = CF(0, 1, 0)
  1533.         Grip.C1 = aimedGripCF
  1534.         headWeld2.C1 = CF(0, -0.5, 0) * CFANG(0, 0, S.aimSettings.headTilt) * CF(0, 0.5, 0)
  1535.         aimAlpha = 1
  1536.         aimHeadOffset = headOffset.X
  1537.         jumpAnimMultiplier = S.fallSettings.aimEffect
  1538.         translationDivisor = 20
  1539.         rotationMultiplier = S.momentumSettings.Amplitude.Aimed
  1540.         armTiltMultiplier = 0.2
  1541.         Cam.FieldOfView = S.aimSettings.FOV
  1542.     end
  1543.     Aiming = (not Aimed)
  1544.     if (not Aiming) and S.guiScope then
  1545.         spawn(function()
  1546.             scopeSteady.Visible = true
  1547.             Scope.BackgroundTransparency = 1
  1548.             scopeMain.Visible = true
  1549.            
  1550.             if armTable then
  1551.                 for _, Obj in pairs(armTable[1].Model:GetChildren()) do
  1552.                     if Obj:IsA("BasePart") then
  1553.                         Obj.LocalTransparencyModifier = 1
  1554.                     end
  1555.                 end
  1556.                 for _, Obj in pairs(armTable[2].Model:GetChildren()) do
  1557.                     if Obj:IsA("BasePart") then
  1558.                         Obj.LocalTransparencyModifier = 1
  1559.                     end
  1560.                 end
  1561.             elseif armModel then
  1562.                 for _, Obj in pairs(armModel:GetChildren()) do
  1563.                     if Obj:IsA("BasePart") then
  1564.                         Obj.LocalTransparencyModifier = 1
  1565.                     end
  1566.                 end
  1567.             end
  1568.             for _, Obj in pairs(playerFolder:GetChildren()) do
  1569.                 if Obj:IsA("BasePart") then
  1570.                     Obj.LocalTransparencyModifier = 1
  1571.                 end
  1572.             end
  1573.             for _, Obj in pairs(Gun:GetChildren()) do
  1574.                 if Obj:IsA("BasePart") then
  1575.                     Obj.LocalTransparencyModifier = 1
  1576.                 end
  1577.             end
  1578.         end)
  1579.         spawn(function()
  1580.             local camAng = 0
  1581.             local idleCam = function()
  1582.                 return V3(
  1583.                     RAD(SIN(camAng * S.scopeSettings.Frequency.Idling)) * stanceSway * camSway * S.scopeSettings.Amplitude.Idling,
  1584.                     RAD(SIN(camAng * 5 / 2 * S.scopeSettings.Frequency.Idling)) * stanceSway * camSway * S.scopeSettings.Amplitude.Idling * 0.75,
  1585.                     0
  1586.                 )
  1587.             end
  1588.             local walkCam = function()
  1589.                 return V3(
  1590.                     RAD(SIN(camAng * S.scopeSettings.Frequency.Walking)) * camSway * stanceSway * S.scopeSettings.Amplitude.Walking,
  1591.                     RAD(SIN(camAng * 5 / 2 * S.scopeSettings.Frequency.Walking)) * camSway * stanceSway * S.scopeSettings.Amplitude.Walking * 0.75,
  1592.                     0
  1593.                 )
  1594.             end
  1595.             while Aimed do
  1596.                 local dt = RS.RenderStepped:wait()
  1597.                 camOffsets.guiScope.Rot = (Sine(idleAlpha) * idleCam()) + (Sine(walkAlpha) * walkCam())
  1598.                 camAng = camAng + RAD(105 * dt) * stanceSway * camSway
  1599.             end
  1600.         end)
  1601.     end
  1602. end
  1603.  
  1604. function unAimGun(Exception)
  1605.     if (not S.canADS) then return end
  1606.    
  1607.     mouseSensitivity = S.sensitivitySettings.Default
  1608.    
  1609.     for _, Plugin in pairs(Plugins.UnAimed) do
  1610.         spawn(function()
  1611.             Plugin()
  1612.         end)
  1613.     end
  1614.    
  1615.     if S.guiScope then
  1616.         spawn(function()
  1617.             if armTable then
  1618.                 for _, Obj in pairs(armTable[1].Model:GetChildren()) do
  1619.                     if Obj:IsA("BasePart") then
  1620.                         Obj.LocalTransparencyModifier = 0
  1621.                     end
  1622.                 end
  1623.                 for _, Obj in pairs(armTable[2].Model:GetChildren()) do
  1624.                     if Obj:IsA("BasePart") then
  1625.                         Obj.LocalTransparencyModifier = 0
  1626.                     end
  1627.                 end
  1628.             elseif armModel then
  1629.                 for _, Obj in pairs(armModel:GetChildren()) do
  1630.                     if Obj:IsA("BasePart") then
  1631.                         Obj.LocalTransparencyModifier = 0
  1632.                     end
  1633.                 end
  1634.             end
  1635.             for _, Obj in pairs(playerFolder:GetChildren()) do
  1636.                 if Obj:IsA("BasePart") then
  1637.                     Obj.LocalTransparencyModifier = 0
  1638.                 end
  1639.             end
  1640.             for _, Obj in pairs(Gun:GetChildren()) do
  1641.                 if Obj:IsA("BasePart") then
  1642.                     Obj.LocalTransparencyModifier = 0
  1643.                 end
  1644.             end
  1645.         end)
  1646.     end
  1647.    
  1648.     if (not Exception) then
  1649.         if (not Aimed) then return end
  1650.         if (Reloading and Exception) or Knifing then return end
  1651.         spreadZoom = "unAimed"
  1652.         baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
  1653.         Aimed = false
  1654.         Aiming = true
  1655.         if S.aimSettings.Anim then
  1656.             local currentFOV = Cam.FieldOfView
  1657.             local currentTrans = (Scope.BackgroundTransparency == 1 and (S.guiScope and 0 or 1) or Scope.BackgroundTransparency)
  1658.             scopeMain.Visible = false
  1659.             scopeSteady.Visible = false
  1660.             tweenJoint(LWeld, armC0[1], S.unAimedC1.leftArm, Sine, S.aimSettings.Speed)
  1661.             tweenJoint(RWeld, armC0[2], S.unAimedC1.rightArm, Sine, S.aimSettings.Speed)
  1662.             tweenJoint(headWeld2, nil, CF(), Sine, S.aimSettings.Speed)
  1663.             tweenJoint(Grip, nil, S.unAimedC1.Grip, Sine, S.aimSettings.Speed)
  1664.             local t0 = tick()
  1665.             while true do
  1666.                 RS.RenderStepped:wait()
  1667.                 local Alpha = math.min((tick() - t0) / S.aimSettings.Speed, 1) * 90
  1668.                 if Aimed then break end
  1669.                 if (not Selected) then break end
  1670.                 aimAlpha = 1 - Sine(Alpha)--1 - COS(RAD(X))
  1671.                 aimHeadOffset = headOffset.X * aimAlpha
  1672.                 jumpAnimMultiplier = numLerp(1, S.fallSettings.aimEffect, aimAlpha)
  1673.                 translationDivisor = numLerp(7, 20, aimAlpha)
  1674.                 rotationMultiplier = numLerp(S.momentumSettings.Amplitude.unAimed, S.momentumSettings.Amplitude.Aimed, aimAlpha)
  1675.                 armTiltMultiplier = numLerp(1, 0.2, aimAlpha)
  1676.                 Cam.FieldOfView = numLerp(80, currentFOV, aimAlpha)
  1677.                 Scope.BackgroundTransparency = numLerp(1, currentTrans, aimAlpha)
  1678.                 if Alpha == 90 then break end
  1679.             end
  1680.         else
  1681.             scopeMain.Visible = false
  1682.             scopeSteady.Visible = false
  1683.             LWeld.C0, LWeld.C1 = armC0[1], S.unAimedC1.leftArm
  1684.             RWeld.C0, RWeld.C1 = armC0[2], S.unAimedC1.rightArm
  1685.             headWeld2.C0 = CF()
  1686.             Grip.C1 = S.unAimedC1.Grip
  1687.             aimAlpha = 0
  1688.             aimHeadOffset = 0
  1689.             jumpAnimMultiplier = 1
  1690.             translationDivisor = 7
  1691.             rotationMultiplier = S.momentumSettings.Amplitude.unAimed
  1692.             armTiltMultiplier = 1
  1693.             Cam.FieldOfView = 80
  1694.             Scope.BackgroundTransparency = 1
  1695.         end
  1696.         Aiming = Aimed
  1697.     else
  1698.         spawn(function()
  1699.             Aimed = false
  1700.             Aiming = false
  1701.             spreadZoom = "unAimed"
  1702.             baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
  1703.             local currentFOV = Cam.FieldOfView
  1704.             local currentTrans = (Scope.BackgroundTransparency == 1 and (S.guiScope and 0 or 1) or Scope.BackgroundTransparency)
  1705.             scopeMain.Visible = false
  1706.             scopeSteady.Visible = false
  1707.             tweenJoint(headWeld2, nil, CF(), Sine, S.aimSettings.Speed)
  1708.             if S.aimSettings.Anim then
  1709.                 local t0 = tick()
  1710.                 while true do
  1711.                     RS.RenderStepped:wait()
  1712.                     local Alpha = math.min((tick() - t0) / S.aimSettings.Speed, 1) * 90
  1713.                     if Aimed then break end
  1714.                     if (not Selected) then break end
  1715.                     aimAlpha = 1 - Sine(Alpha)--1 - COS(RAD(90 - Alpha))
  1716.                     aimHeadOffset = headOffset.X * aimAlpha
  1717.                     jumpAnimMultiplier = numLerp(1, S.fallSettings.aimEffect, aimAlpha)
  1718.                     translationDivisor = numLerp(7, 20, aimAlpha)
  1719.                     rotationMultiplier = numLerp(S.momentumSettings.Amplitude.unAimed, S.momentumSettings.Amplitude.Aimed, aimAlpha)
  1720.                     armTiltMultiplier = numLerp(1, 0.2, aimAlpha)
  1721.                     Cam.FieldOfView = numLerp(80, currentFOV, aimAlpha)
  1722.                     Scope.BackgroundTransparency = numLerp(1, currentTrans, aimAlpha)
  1723.                     if Alpha == 90 then break end
  1724.                 end
  1725.             else
  1726.                 scopeMain.Visible = false
  1727.                 scopeSteady.Visible = false
  1728.                 aimAlpha = 0
  1729.                 aimHeadOffset = 0
  1730.                 jumpAnimMultiplier = 1
  1731.                 translationDivisor = 7
  1732.                 rotationMultiplier = S.momentumSettings.Amplitude.unAimed
  1733.                 armTiltMultiplier = 1
  1734.                 Cam.FieldOfView = 80
  1735.                 Scope.BackgroundTransparency = 1
  1736.             end
  1737.         end)
  1738.     end
  1739. end
  1740.  
  1741. --------------------[ TEXTURE CREATION FUNCTIONS ]------------------------------------
  1742.  
  1743. function createBullet(Direction)
  1744.     local Origin = Gun.Main.CFrame.p
  1745.     local bulletCF = CF(Origin, Origin + Direction)
  1746.     local Bullet = Instance.new("Part")
  1747.     Bullet.BrickColor = S.bulletSettings.Color
  1748.     Bullet.Material = Enum.Material.Neon
  1749.     Bullet.Name = "Bullet"
  1750.     Bullet.CanCollide = false
  1751.     Bullet.FormFactor = "Custom"
  1752.     Bullet.Size = S.bulletSettings.Size
  1753.     Bullet.BottomSurface = "Smooth"
  1754.     Bullet.TopSurface = "Smooth"
  1755.     if math.min(S.bulletSettings.Size.X, S.bulletSettings.Size.Y, S.bulletSettings.Size.Z) < 0.2 then
  1756.         local Mesh = Instance.new("BlockMesh")
  1757.         Mesh.Scale = S.bulletSettings.Size / Vector3.new(
  1758.             math.max(S.bulletSettings.Size.X, 0.2),
  1759.             math.max(S.bulletSettings.Size.Y, 0.2),
  1760.             math.max(S.bulletSettings.Size.Z, 0.2)
  1761.         )
  1762.         Mesh.Parent = Bullet
  1763.     end
  1764.     local BF = Instance.new("BodyForce")
  1765.     BF.force = V3(0, Bullet:GetMass() * (196.2 - S.bulletSettings.Acceleration), 0)
  1766.     BF.Parent = Bullet
  1767.     Bullet.Parent = gunIgnore
  1768.     Bullet.CFrame = bulletCF + Direction * S.bulletSettings.Size.Z / 2
  1769.     Bullet.Velocity = Direction * S.bulletSettings.Velocity
  1770.     return Bullet
  1771. end
  1772.  
  1773. --------------------[ HIT HANDLING FUNCTIONS ]----------------------------------------
  1774.  
  1775. function getBaseDamage(Dist)
  1776.     local startDmg = S.damageSettings.Start.Damage
  1777.     local startDist = S.damageSettings.Start.Dist
  1778.     local endDmg = S.damageSettings.End.Damage
  1779.     local endDist = S.damageSettings.End.Dist
  1780.     return (
  1781.         (
  1782.             Dist < startDist * S.bulletSettings.Range
  1783.         ) and startDmg or
  1784.         (
  1785.             Dist >= startDist * S.bulletSettings.Range and
  1786.             Dist < endDist * S.bulletSettings.Range
  1787.         ) and numLerp(startDmg, endDmg, Map(Dist / S.bulletSettings.Range, startDist, endDist, 0, 1)) or
  1788.         (
  1789.             Dist >= endDist * S.bulletSettings.Range
  1790.         ) and endDmg
  1791.     )
  1792. end
  1793.  
  1794. function Damage(H, P, N, D, Dist, customIgnore)
  1795.     local hVal = S.damageSettings.Multipliers.Head
  1796.     local cVal = S.damageSettings.Multipliers.Chest
  1797.     local lVal = S.damageSettings.Multipliers.Limbs
  1798.     local baseDamage = getBaseDamage(Dist)
  1799.     if Humanoid.Health ~= 0 then
  1800.         local hitHumanoid = nil
  1801.         if H.Parent:IsA("Hat") then
  1802.             table.insert(customIgnore, H)
  1803.             local newRay = Ray.new(P - D * 0.1, D * (S.bulletSettings.Range - Dist + 0.1))
  1804.             local newH, newP, newN = workspace:FindPartOnRayWithIgnoreList(newRay, customIgnore)
  1805.             if newH then
  1806.                 hitHumanoid = Damage(newH, newP, newN, D, Dist + (newP - P).magnitude, customIgnore)
  1807.             end
  1808.         else
  1809.             hitHumanoid = findFirstClass(H.Parent, "Humanoid")
  1810.             if hitHumanoid and hitHumanoid.Health > 0 and isEnemy(hitHumanoid) then
  1811.                 local Tag = Instance.new("ObjectValue")
  1812.                 Tag.Value = Player
  1813.                 Tag.Name = "creator"
  1814.                 Tag.Parent = hitHumanoid
  1815.                 DS:AddItem(Tag, 0.3)
  1816.                 local chosenDamage = 0
  1817.                 if H.Name == "Head" then
  1818.                     chosenDamage = baseDamage  * RAND(hVal, hVal + 0.1, 0.01)
  1819.                 elseif H.Name == "Torso" then
  1820.                     chosenDamage = baseDamage  * RAND(cVal, cVal + 0.1, 0.01)
  1821.                 else
  1822.                     chosenDamage = baseDamage  * RAND(lVal, lVal + 0.1, 0.01)
  1823.                 end
  1824.                 hitHumanoid:TakeDamage(chosenDamage)
  1825.                 markHit()
  1826.             end
  1827.         end
  1828.         return hitHumanoid
  1829.     end
  1830. end
  1831.  
  1832. function isWallIgnored(Wall)
  1833.     return (
  1834.         Wall.Transparency >= S.penetrationSettings.transparencyThreshold or
  1835.         (S.penetrationSettings.ignoreNonCanCollide and (not Wall.CanCollide)) or
  1836.         isIgnored(Wall, S.penetrationSettings.ignoreCustom)
  1837.     )
  1838. end
  1839.  
  1840. function penetrateWall(Wall, hitPos, Direction, Normal, Ignore, totalPDist, totalBDist, lastDamagedHumanoid)
  1841.     local wallIgnore = isWallIgnored(Wall)
  1842.     local hitHumanoid = (Wall.Parent:IsA("Hat") and findFirstClass(Wall.Parent.Parent, "Humanoid") or findFirstClass(Wall.Parent, "Humanoid"))
  1843.     local damagedHumanoid = nil
  1844.     if hitHumanoid and hitHumanoid ~= lastDamagedHumanoid then
  1845.         lastDamagedHumanoid = hitHumanoid
  1846.         damagedHumanoid = Damage(Wall, hitPos, Normal, Direction, totalBDist, {Char, ignoreModel})
  1847.     else
  1848.         lastDamagedHumanoid = nil
  1849.     end
  1850.     local ignoreObject = hitHumanoid and (Wall.Parent:IsA("Hat") and Wall.Parent.Parent or Wall.Parent) or Wall
  1851.     table.insert(Ignore, ignoreObject)
  1852.     local rayLength = S.bulletSettings.Range - totalBDist
  1853.     local testRay = Ray.new(hitPos, Direction * (S.bulletSettings.Range - totalBDist))
  1854.     local H1, P1, N1 = workspace:FindPartOnRayWithIgnoreList(testRay, Ignore)
  1855.     local newIgnore = removeElement(Ignore, ignoreObject)
  1856.     local wallRay = Ray.new(P1 + Direction * 0.1, -Direction * (rayLength + 1))
  1857.     local H2, P2, N2 = workspace:FindPartOnRayWithIgnoreList(wallRay, Ignore)
  1858.     local newPDist = totalPDist + (wallIgnore and 0 or (getNearestPoint(P1, P2, hitPos) - hitPos).magnitude)
  1859.     local newBDist = totalBDist + (P1 - hitPos).magnitude
  1860.     local outOfRange = Round(newPDist, 0.001) > S.penetrationSettings.Dist or Round(newBDist, 0.001) > S.bulletSettings.Range
  1861.     if (not wallIgnore) then
  1862.         createBulletImpact:FireServer(Wall, hitPos, Normal, Direction, hitHumanoid, gunIgnore, S)
  1863.         if (not hitHumanoid) then
  1864.             createShockwave:FireServer(hitPos, S.shockwaveSettings.Radius, gunIgnore, S)
  1865.         end
  1866.     end
  1867.     if hitHumanoid and hitHumanoid.Health > 0 and isEnemy(hitHumanoid) and hitHumanoid == damagedHumanoid then
  1868.         createBlood:FireServer(Wall, P2, Direction, gunIgnore, S)
  1869.     end
  1870.     if outOfRange or (not H1) then
  1871.         if (not outOfRange) and (not wallIgnore) then
  1872.             createBulletImpact:FireServer(Wall, P2, N2, Direction, hitHumanoid, gunIgnore, S)
  1873.             if (not hitHumanoid) then
  1874.                 createShockwave:FireServer(P2, S.shockwaveSettings.Radius, gunIgnore, S)
  1875.             end
  1876.         end
  1877.         return Wall, hitPos
  1878.     else
  1879.         if Wall == H2 and (not wallIgnore) then
  1880.             createBulletImpact:FireServer(Wall, P2, N2, Direction, hitHumanoid, gunIgnore, S)
  1881.             if (not hitHumanoid) then
  1882.                 createShockwave:FireServer(P2, S.shockwaveSettings.Radius, gunIgnore, S)
  1883.             end
  1884.         end
  1885.         return penetrateWall(H1, P1, Direction, N1, Ignore, newPDist, newBDist, lastDamagedHumanoid)
  1886.     end
  1887. end
  1888.  
  1889. function PenetrateWall(HitPos, Direction, HitHumanoid, OriginPos, Bullet, CurrentPDist)
  1890.     local HitDist = (HitPos - OriginPos).magnitude
  1891.     local Wall, WallHitPos = nil, nil
  1892.     local Hum, HumHitPos = nil, nil
  1893.     local CustomIgnore = {unpack(Ignore)}
  1894.     for i = 1, 10 do
  1895.         local WallRay = Ray.new(HitPos - (Direction * 0.1), Direction * S.Penetration)
  1896.         local H, P = game.Workspace:FindPartOnRayWithIgnoreList(WallRay, CustomIgnore)
  1897.         if H then
  1898.             local HitHumanoid = nil
  1899.             if H.Parent.ClassName == "Hat" then
  1900.                 HitHumanoid = findFirstClass(H.Parent.Parent, "Humanoid")
  1901.             else
  1902.                 HitHumanoid = findFirstClass(H.Parent, "Humanoid")
  1903.             end
  1904.             if HitHumanoid and i ~= 1 then
  1905.                 Hum, HumHitPos = H, P
  1906.                 break
  1907.             else
  1908.                 Wall, WallHitPos = H, P
  1909.                 table.insert(CustomIgnore, H)
  1910.             end
  1911.         else
  1912.             break
  1913.         end
  1914.     end
  1915.     if Wall then
  1916.         if S.InstantHit then
  1917.             if Hum then
  1918.                 Damage(Hum.Parent:FindFirstChild("Head"), HumHitPos)
  1919.                 return HumHitPos
  1920.             else
  1921.                 local HitObj2, HitPos2 = nil, nil
  1922.                 if HitHumanoid then
  1923.                     HitObj2, HitPos2 = AdvRayCast(WallHitPos, Direction, S.BulletRange - HitDist, {Wall, HitHumanoid.Parent, unpack(Ignore)})
  1924.                 else
  1925.                     HitObj2, HitPos2 = AdvRayCast(WallHitPos, Direction, S.BulletRange - HitDist, {Wall, unpack(Ignore)})
  1926.                 end
  1927.                 Damage(HitObj2, HitPos2)
  1928.                
  1929.                 local NewPDist = CurrentPDist + (WallHitPos - HitPos).magnitude
  1930.                 local NewHitPos2 = HitPos2
  1931.                 if NewPDist < S.Penetration and HitObj2 then
  1932.                     NewHitPos2 = PenetrateWall(HitPos2, Direction, HitHumanoid, OriginPos, Bullet, CurrentPDist + NewPDist)
  1933.                 end
  1934.                 return NewHitPos2
  1935.             end
  1936.         else
  1937.             local LastPos = WallHitPos
  1938.             local TotalDistTraveled = 0
  1939.             spawn(function()
  1940.                 if Hum then
  1941.                     Damage(Hum.Parent:FindFirstChild("Head"), HumHitPos)
  1942.                     return HumHitPos
  1943.                 else
  1944.                     while true do
  1945.                         RS.RenderStepped:wait()
  1946.                         if TotalDistTraveled >= S.BulletRange - HitDist then
  1947.                             Bullet:Destroy()
  1948.                             break
  1949.                         end
  1950.                         local DistTraveled = (Bullet.Position - LastPos).magnitude
  1951.                         local NewDirection = (Bullet.Position - LastPos).unit
  1952.                         local TempHitObj, TempHitPos = nil, nil
  1953.                         if HitHumanoid then
  1954.                             TempHitObj, TempHitPos = AdvRayCast(LastPos, NewDirection, DistTraveled, {Wall, HitHumanoid.Parent, unpack(Ignore)})
  1955.                         else
  1956.                             TempHitObj, TempHitPos = AdvRayCast(LastPos, NewDirection, DistTraveled, {Wall, unpack(Ignore)})
  1957.                         end
  1958.                         if TempHitObj then
  1959.                             Damage(TempHitObj, TempHitPos)
  1960.                            
  1961.                             local NewPDist = CurrentPDist + (WallHitPos - HitPos).magnitude
  1962.                             local NewTempPos = TempHitPos
  1963.                             if NewPDist < S.Penetration and TempHitObj then
  1964.                                 NewTempPos = PenetrateWall(TempHitPos, Direction, HitHumanoid, OriginPos, Bullet, CurrentPDist + NewPDist)
  1965.                             else
  1966.                                 Bullet:Destroy()
  1967.                             end
  1968.                             return NewTempPos
  1969.                         else
  1970.                             LastPos = Bullet.Position
  1971.                             TotalDistTraveled = TotalDistTraveled + DistTraveled
  1972.                         end
  1973.                     end
  1974.                 end
  1975.             end)
  1976.         end
  1977.     else
  1978.         if Bullet then Bullet:Destroy() end
  1979.         return HitPos
  1980.     end
  1981. end
  1982.  
  1983. function isEnemy(Human)
  1984.     local Plyr = game.Players:GetPlayerFromCharacter(Human.Parent)
  1985.     if (not Plyr) then return S.CanDamageNPCs end
  1986.     return S.AllowFriendlyFire or (Plyr.TeamColor ~= Player.TeamColor or Plyr.Neutral)
  1987. end
  1988.  
  1989. --------------------[ RELOAD FUNCTIONS ]----------------------------------------------
  1990.  
  1991. function animateReload()
  1992.     tweenJoint(LWeld2, CF(), CF(), Sine, 0.15)
  1993.     tweenJoint(RWeld2, CF(), CF(), Sine, 0.15)
  1994.     local magParts = {}
  1995.     local magTable = {}
  1996.            
  1997.     for _, Obj in pairs(Gun:GetChildren()) do
  1998.         if string.sub(Obj.Name, 1, 3) == "Mag" and Obj:IsA("BasePart") then
  1999.             INSERT(magParts, Obj)
  2000.         end
  2001.     end
  2002.    
  2003.     local animVars = {
  2004.         --FUNCTIONS--
  2005.         tweenJoint = tweenJoint;
  2006.        
  2007.         makeMagInvisible = function()
  2008.             for _, v in pairs(magParts) do
  2009.                 v.Transparency = 1
  2010.             end
  2011.             magVisible = false
  2012.         end;
  2013.        
  2014.         makeMagVisible = function()
  2015.             for _, v in pairs(magParts) do
  2016.                 v.Transparency = v:WaitForChild("magTrans").Value
  2017.             end
  2018.             magVisible = true
  2019.         end;
  2020.        
  2021.         isMagVisible = function()
  2022.             return magVisible
  2023.         end;
  2024.        
  2025.         isMagEmpty = function()
  2026.             return ammoInClip == 0
  2027.         end;
  2028.        
  2029.         setNewMag = function()
  2030.             newMag = true
  2031.         end;
  2032.        
  2033.         isNewMag = function()
  2034.             return newMag
  2035.         end;
  2036.        
  2037.         createMag = function(Key)
  2038.             local magModel = Instance.new("Model")
  2039.             local magClones = {}
  2040.             for i, v in pairs(magParts) do
  2041.                 local vClone = v:Clone()
  2042.                 vClone.Transparency = v:WaitForChild("magTrans").Value
  2043.                 vClone.CanCollide = false
  2044.                 vClone.Parent = magModel
  2045.                 INSERT(magClones, {Original = v, magClone = vClone})
  2046.                 if i ~= 1 then
  2047.                     local W = Instance.new("Weld")
  2048.                     W.Part0 = magClones[1].magClone
  2049.                     W.Part1 = vClone
  2050.                     W.C0 = magClones[1].magClone.CFrame:toObjectSpace(vClone.CFrame)
  2051.                     W.Parent = magClones[1].magClone
  2052.                 end
  2053.             end
  2054.             magTable[Key] = {magModel, magClones}
  2055.             return magModel, magClones
  2056.         end;
  2057.        
  2058.         getMag = function(Key)
  2059.             if magTable[Key] then
  2060.                 return magTable[Key][1], magTable[Key][2]
  2061.             else
  2062.                 return nil, nil
  2063.             end
  2064.         end;
  2065.        
  2066.         attachGripToHead = function()
  2067.             local handleCF = RArm.CFrame * Grip.C0
  2068.             Grip.C0 = Head.CFrame:toObjectSpace(handleCF)
  2069.             Grip.Part0 = Head
  2070.         end;
  2071.        
  2072.         attachGripToArm = function()
  2073.             local handleCF = Head.CFrame * Grip.C0
  2074.             Grip.C0 = RArm.CFrame:toObjectSpace(handleCF)
  2075.             Grip.Part0 = RArm
  2076.         end;
  2077.        
  2078.         Sine = Sine;
  2079.        
  2080.         Linear = Linear;
  2081.        
  2082.         --VARIABLES--
  2083.         Handle = Handle;
  2084.         LArm = LArm;
  2085.         RArm = RArm;
  2086.         LWeld = LWeld;
  2087.         RWeld = RWeld;
  2088.         LC0 = armC0[1];
  2089.         RC0 = armC0[2];
  2090.         Grip = Grip;
  2091.         gunIgnore = gunIgnore;
  2092.         Cam = Cam;
  2093.         CF = CF;
  2094.         CFANG = CFANG;
  2095.         V3 = V3;
  2096.         RAD = RAD;
  2097.         reloadTimeLoaded = S.reloadSettings.Times.Loaded;
  2098.         reloadTimeEmpty = S.reloadSettings.Times.Empty
  2099.     }
  2100.    
  2101.     local sequenceTable = Anims.Reload(animVars)
  2102.     --local T = tick()
  2103.     for _, reloadFunction in pairs(sequenceTable) do
  2104.         if breakReload then
  2105.             break
  2106.         end
  2107.         reloadFunction()
  2108.        
  2109.         if (not magVisible) then
  2110.             Ammo.Value = 0
  2111.         end
  2112.         updateClipAmmo()
  2113.     end
  2114.     --print(tick() - T) --I divide the reloadTime by this number to get the animation speed
  2115.    
  2116.     if (not isCrawling) then
  2117.         if Running and (not S.canFireWhileRunning) then
  2118.             tweenJoint(LWeld, armC0[1], S.runningC1.leftArm, Sine, 0.4)
  2119.             tweenJoint(RWeld, armC0[2], S.runningC1.rightArm, Sine, 0.4)
  2120.             tweenJoint(Grip, nil, S.runningC1.Grip, Sine, 0.4)
  2121.         else
  2122.             tweenJoint(LWeld, armC0[1], S.unAimedC1.leftArm, Sine, 0.4)
  2123.             tweenJoint(RWeld, armC0[2], S.unAimedC1.rightArm, Sine, 0.4)
  2124.             tweenJoint(Grip, nil, S.unAimedC1.Grip, Sine, 0.4)
  2125.         end
  2126.     end
  2127.    
  2128.     for _, v in pairs(magTable) do --In case the reload animations was stopped mid way and there were still fake mags that weren't deleted
  2129.         v[1]:Destroy()
  2130.     end
  2131. end
  2132.  
  2133. function Reload()
  2134.     if Ammo.Value < (ClipSize.Value + 1) and (not Reloading) and StoredAmmo.Value > 0 then
  2135.         Firing = false
  2136.         ammoInClip = (ammoInClip == 0 and Ammo.Value or ammoInClip)
  2137.         Reloading = true
  2138.         lowerSpread()
  2139.         if Aimed then unAimGun(S.reloadSettings.Anim) end
  2140.         crossHair.Reload.Visible = true
  2141.         if Handle:FindFirstChild("ReloadSound") then Handle.ReloadSound:Play() end
  2142.         if S.reloadSettings.Anim then
  2143.             wait()
  2144.             animateReload()
  2145.         else
  2146.             local startReload = tick()
  2147.             local initialReloadTime = Ammo.Value == 0 and S.reloadSettings.Times.Empty or S.reloadSettings.Times.Loaded
  2148.             while true do
  2149.                 if breakReload then break end
  2150.                 if (tick() - startReload) >= initialReloadTime then break end
  2151.                 RS.RenderStepped:wait()
  2152.             end
  2153.         end
  2154.         if (not breakReload) then
  2155.             newMag = false
  2156.             if StoredAmmo.Value >= ClipSize.Value then
  2157.                 if ammoInClip > 0 then
  2158.                     StoredAmmo.Value = StoredAmmo.Value - ((ClipSize.Value + 1) - ammoInClip)
  2159.                     Ammo.Value = ClipSize.Value + 1
  2160.                 else
  2161.                     StoredAmmo.Value = StoredAmmo.Value - ClipSize.Value
  2162.                     Ammo.Value = ClipSize.Value
  2163.                 end
  2164.             elseif StoredAmmo.Value < ClipSize.Value and StoredAmmo.Value > 0 then
  2165.                 Ammo.Value = StoredAmmo.Value
  2166.                 StoredAmmo.Value = 0
  2167.             end
  2168.         end
  2169.         Reloading = false
  2170.         if Selected then
  2171.             ammoInClip = (breakReload and ammoInClip or 0)
  2172.             crossHair.Reload.Visible = false
  2173.         end
  2174.         breakReload = false
  2175.     end
  2176.    
  2177.     updateClipAmmo()
  2178.     updateStoredAmmo()
  2179. end
  2180.  
  2181. --------------------[ EXTERNAL DATA LOCATING FUNCTIONS ]-----------------------------
  2182.  
  2183. function removeElement(Table, Element) --removes the first instance of Element from Table
  2184.     for i, v in pairs(Table) do
  2185.         if v == Element then
  2186.             table.remove(Table, i)
  2187.             break
  2188.         end
  2189.     end
  2190.     return Table
  2191. end
  2192.  
  2193. function findFirstClass(Object, Class)
  2194.     local foundObject = nil
  2195.     for _, Obj in pairs(Object:GetChildren()) do
  2196.         if Obj.ClassName == Class then
  2197.             foundObject = Obj
  2198.             break
  2199.         end
  2200.     end
  2201.     return foundObject
  2202. end
  2203.  
  2204. function isIgnored(Obj, Table)
  2205.     for _,v in pairs(Table) do
  2206.         if Obj == v or Obj:IsDescendantOf(v) then
  2207.             return true
  2208.         end
  2209.     end
  2210.     return false
  2211. end
  2212.  
  2213. function GetHitSurfaceCFrame(HitPos,Obj)
  2214.     local SurfaceCF = {
  2215.         {"Back",Obj.CFrame * CF(0,0,Obj.Size.z)};
  2216.         {"Bottom",Obj.CFrame * CF(0,-Obj.Size.y,0)};
  2217.         {"Front",Obj.CFrame * CF(0,0,-Obj.Size.z)};
  2218.         {"Left",Obj.CFrame * CF(-Obj.Size.x,0,0)};
  2219.         {"Right",Obj.CFrame * CF(Obj.Size.x,0,0)};
  2220.         {"Top",Obj.CFrame * CF(0,Obj.Size.y,0)}
  2221.     }
  2222.     local ClosestDist = HUGE
  2223.     local ClosestSurface = nil
  2224.     for _,v in pairs(SurfaceCF) do
  2225.         local SurfaceDist = (HitPos - v[2].p).magnitude
  2226.         if SurfaceDist < ClosestDist then
  2227.             ClosestDist = SurfaceDist
  2228.             ClosestSurface = v
  2229.         end
  2230.     end
  2231.     return ClosestSurface[2]
  2232. end
  2233.  
  2234. function AdvRayCast(Origin, Direction, Dist, CustomIgnore)
  2235.     local NewIgnore = (CustomIgnore and CustomIgnore or Ignore)
  2236.     local NewRay = Ray.new(Origin, Direction * (Dist > 999 and 999 or Dist))
  2237.     local HitObj, HitPos = game.Workspace:FindPartOnRayWithIgnoreList(NewRay, NewIgnore)
  2238.     local LastPos = HitPos
  2239.     local FinalHitObj, FinalHitPos = nil, nil
  2240.     local RepTimes = math.floor(Dist / 999)
  2241.     if (not HitObj) and (Dist > 999) then
  2242.         for i = 0, RepTimes do
  2243.             local NewDist = (i == RepTimes and  (Dist - (LastPos - Origin).magnitude) or 999)
  2244.             local Ray2 = Ray.new(LastPos, Direction * NewDist)
  2245.             local HitObj2, HitPos2 = game.Workspace:FindPartOnRayWithIgnoreList(Ray2, NewIgnore)
  2246.             if i ~= RepTimes then
  2247.                 if HitObj2 then
  2248.                     FinalHitObj, FinalHitPos = HitObj2, HitPos2
  2249.                     break
  2250.                 end
  2251.             elseif i == RepTimes then
  2252.                 FinalHitObj, FinalHitPos = HitObj2, HitPos2
  2253.             end
  2254.             LastPos = HitPos2
  2255.         end
  2256.         return FinalHitObj, FinalHitPos
  2257.     elseif HitObj or (Dist <= 999) then
  2258.         return HitObj, HitPos
  2259.     end
  2260. end
  2261.  
  2262. --------------------[ JUMPING ANIMATION ]---------------------------------------------
  2263.  
  2264. function onFall(initialVelocity)
  2265.     spawn(function()
  2266.         local velocityAlpha = math.max(math.min(initialVelocity / Humanoid.JumpPower, 1), 0)
  2267.         local startJumpPos = jumpAnim.Pos
  2268.         local startJumpRot = jumpAnim.Rot
  2269.         local endJumpPos = 0.04 * S.fallSettings.fallMultiplier * velocityAlpha
  2270.         local endJumpRot = RAD(4) * S.fallSettings.fallMultiplier * velocityAlpha
  2271.         local t0 = tick()
  2272.         while true do
  2273.             RS.Heartbeat:wait()
  2274.             local Alpha = math.min((tick() - t0) / 0.15, 1) * 90
  2275.             if onGround then break end
  2276.             jumpAnim.Pos = numLerp(startJumpPos, endJumpPos, Sine(Alpha))
  2277.             jumpAnim.Rot = numLerp(startJumpRot, endJumpRot, Sine(Alpha))
  2278.             if Alpha == 90 then break end
  2279.         end
  2280.         startJumpPos = endJumpPos
  2281.         startJumpRot = endJumpRot
  2282.         endJumpPos = -0.08 * S.fallSettings.fallMultiplier
  2283.         endJumpRot = -RAD(8) * S.fallSettings.fallMultiplier
  2284.         local X = 1
  2285.         while true do
  2286.             local dt = RS.Heartbeat:wait()
  2287.             X = X + (dt * 60) / X
  2288.             local Alpha = (X - 1) / 15
  2289.             if onGround then break end
  2290.             jumpAnim.Pos = numLerp(startJumpPos, endJumpPos, Alpha)
  2291.             jumpAnim.Rot = numLerp(startJumpRot, endJumpRot, Alpha)
  2292.         end
  2293.     end)
  2294. end
  2295.  
  2296. function onLand(fallDist)
  2297.     spawn(function()
  2298.         local animAlpha = math.min(fallDist, S.fallSettings.maxDist) * (2 / 3)
  2299.         local startJumpPos = jumpAnim.Pos
  2300.         local startJumpRot = jumpAnim.Rot
  2301.         local endJumpPos = animAlpha / 100 * S.fallSettings.landMultiplier * (runReady and 1 or 2)
  2302.         local endJumpRot = RAD(animAlpha) * S.fallSettings.landMultiplier * (runReady and 1 or 2)
  2303.         local t0 = tick()
  2304.         while true do
  2305.             RS.Heartbeat:wait()
  2306.             local Alpha = math.min((tick() - t0) / 0.2, 1)
  2307.             if (not onGround) then break end
  2308.             jumpAnim.Pos = numLerp(startJumpPos, endJumpPos, Alpha)
  2309.             jumpAnim.Rot = numLerp(startJumpRot, endJumpRot, Alpha)
  2310.             if Alpha == 1 then break end
  2311.         end
  2312.         t0 = tick()
  2313.         while true do
  2314.             RS.Heartbeat:wait()
  2315.             local Alpha = math.min((tick() - t0) / 0.3, 1) * 90
  2316.             if (not onGround) then break end
  2317.             jumpAnim.Pos = numLerp(endJumpPos, 0, Sine(Alpha))
  2318.             jumpAnim.Rot = numLerp(endJumpRot, 0, Sine(Alpha))
  2319.             if Alpha == 90 then break end
  2320.         end
  2321.     end)
  2322. end
  2323.  
  2324. function onHumanoidStateChanged(oldState, newState)
  2325.     if newState == Enum.HumanoidStateType.Freefall then
  2326.         onGround = false
  2327.         if S.fallAnimation then
  2328.             onFall(HRP.Velocity.Y)
  2329.             while HRP.Velocity.Y > 0 do RS.RenderStepped:wait() end
  2330.             startFallHeight = HRP.Position.Y
  2331.         end
  2332.     elseif oldState == Enum.HumanoidStateType.Freefall then
  2333.         onGround = true
  2334.         if S.fallAnimation then
  2335.             local fallDist = startFallHeight - HRP.Position.Y
  2336.             onLand(fallDist)
  2337.         end
  2338.     end
  2339. end
  2340. --------------------[ CAMERA STEADYING FUNCTIONS ]------------------------------------
  2341.  
  2342. function steadyCamera()
  2343.     scopeSteady.Text = "Steadying..."
  2344.     scopeSteady.TextColor3 = Color3.new(1, 1, 0)
  2345.     camSteady = true
  2346.     local originalSway = camSway
  2347.     local Increment = 1.5 / 0.6
  2348.     local X = 0
  2349.     while true do
  2350.         RS.RenderStepped:wait()
  2351.         local newX = X + Increment
  2352.         X = (newX > 90 and 90 or newX)
  2353.         if (not steadyKeyPressed) then break end
  2354.         camSway = numLerp(originalSway, 0, Sine(X))
  2355.         if X == 90 then break end
  2356.     end
  2357.     while steadyKeyPressed and Aimed do
  2358.         if currentSteadyTime > 0 then
  2359.             local NewSteadyTime = currentSteadyTime - 1
  2360.             currentSteadyTime = (NewSteadyTime < 0 and 0 or NewSteadyTime)
  2361.             camSway = 0
  2362.         elseif currentSteadyTime == 0 then
  2363.             break
  2364.         end
  2365.         RS.RenderStepped:wait()
  2366.     end
  2367.     camSteady = false
  2368.     spawn(function()
  2369.         local Increment = 1.5 / 0.25
  2370.         local X = 0
  2371.         while true do
  2372.             RS.RenderStepped:wait()
  2373.             local newX = X + Increment
  2374.             X = (newX > 90 and 90 or newX)
  2375.             if camSteady then break end
  2376.             camSway = numLerp(0, S.scopeSettings.camSwayOnBreath, 1 - COS(RAD(X)))
  2377.             if X == 90 then break end
  2378.         end
  2379.         Increment = 1.5 / S.scopeSettings.breathTime
  2380.         X = 0
  2381.         while true do
  2382.             RS.RenderStepped:wait()
  2383.             local newX = X + Increment
  2384.             X = (newX > 90 and 90 or newX)
  2385.             if camSteady then break end
  2386.             camSway = numLerp(S.scopeSettings.camSwayOnBreath, 1, Sine(X))
  2387.             if X == 90 then break end
  2388.         end
  2389.         --[[for X = 0, 90, 1.5 / 0.2 do
  2390.             local Alpha = 1 - COS(RAD(X))--math.log10(X) / math.log10(90)
  2391.             camSway = numLerp(0, 3, Alpha)
  2392.             RS.RenderStepped:wait()
  2393.         end]]
  2394.         --[[for X = 0, 90, 1.5 / S.scopeSettings.steadyTime do
  2395.             if camSteady then break end
  2396.             local Alpha = SIN(RAD(X))
  2397.             camSway = numLerp(3, 1, Alpha)
  2398.             RS.RenderStepped:wait()
  2399.         end]]
  2400.     end)
  2401.     retakeBreath()
  2402. end
  2403.  
  2404. function retakeBreath()
  2405.     scopeSteady.Text = "Re-taking Breath"
  2406.     scopeSteady.TextColor3 = Color3.new(1, 0, 0)
  2407.     takingBreath = true
  2408.     local Increment = S.scopeSettings.steadyTime / S.scopeSettings.breathTime
  2409.     while takingBreath do
  2410.         if currentSteadyTime < maxSteadyTime then
  2411.             local newSteadyTime = currentSteadyTime + Increment
  2412.             currentSteadyTime = (newSteadyTime > maxSteadyTime and maxSteadyTime or newSteadyTime)
  2413.         elseif currentSteadyTime >= maxSteadyTime then
  2414.             break
  2415.         end
  2416.         RS.RenderStepped:wait()
  2417.     end
  2418.     if takingBreath then
  2419.         scopeSteady.Text = "Hold "..convertKey(S.Keys.scopeSteady).." to Steady"
  2420.         scopeSteady.TextColor3 = Color3.new(1, 1, 0)
  2421.         takingBreath = false
  2422.     end
  2423. end
  2424.  
  2425. --------------------[ SPRINTING FUNCTIONS ]-------------------------------------------
  2426.  
  2427. function canRun(midRun)
  2428.     return ((Forward and (not Backward)) and
  2429.         Walking and (Stamina > 0) and Running and
  2430.         Selected and (midRun and true or onGround) and
  2431.         runReady and (S.canFireWhileRunning and true or (not Firing))
  2432.     )
  2433. end
  2434.  
  2435. function monitorStamina()
  2436.     Running = true
  2437.     if (not canRun(false)) then
  2438.         Running = false
  2439.         return
  2440.     end
  2441.     if Aimed then unAimGun(true) end
  2442.     if Stance == 1 or Stance == 2 then Stand() end
  2443.     if (not (Reloading and S.reloadSettings.Anim)) then
  2444.         if S.canFireWhileRunning then
  2445.             tweenJoint(LWeld, armC0[1], S.unAimedC1.leftArm, Sine, 0.4)
  2446.             tweenJoint(RWeld, armC0[2], S.unAimedC1.rightArm, Sine, 0.4)
  2447.             tweenJoint(Grip, nil, S.unAimedC1.Grip, Sine, 0.4)
  2448.         else
  2449.             tweenJoint(LWeld, armC0[1], S.runningC1.leftArm, Sine, 0.4)
  2450.             tweenJoint(RWeld, armC0[2], S.runningC1.rightArm, Sine, 0.4)
  2451.             tweenJoint(Grip, nil, S.runningC1.Grip, Sine, 0.4)
  2452.         end
  2453.     end
  2454.     crossOffset = 50
  2455.     while runKeyPressed do
  2456.         if canRun(true) then
  2457.             if onGround then
  2458.                 local newStamina = Stamina - 1
  2459.                 Stamina = (newStamina < 0 and 0 or newStamina)
  2460.             end
  2461.         else
  2462.             break
  2463.         end
  2464.         RS.RenderStepped:wait()
  2465.     end
  2466.     Running = false
  2467.     if (not Aimed) and (not (Reloading and S.reloadSettings.Anim)) and (not S.canFireWhileRunning) then
  2468.         crossOffset = 0
  2469.         tweenJoint(LWeld, armC0[1], S.unAimedC1.leftArm, Sine, 0.4)
  2470.         tweenJoint(RWeld, armC0[2], S.unAimedC1.rightArm, Sine, 0.4)
  2471.         tweenJoint(Grip, nil, S.unAimedC1.Grip, Sine, 0.4)
  2472.     end
  2473.    
  2474.     rechargeStamina()
  2475. end
  2476.  
  2477. function rechargeStamina()
  2478.     chargingStamina = true
  2479.     while ((not runKeyPressed) or (Stamina < maxStamina)) and (not Running) do
  2480.         if Stamina < maxStamina then
  2481.             local newStamina = Stamina + (S.sprintTime / S.staminaCoolTime)
  2482.             Stamina = (newStamina > maxStamina and maxStamina or newStamina)
  2483.         elseif Stamina >= maxStamina then
  2484.             break
  2485.         end
  2486.         RS.RenderStepped:wait()
  2487.     end
  2488.     chargingStamina = false
  2489. end
  2490.  
  2491. --------------------[ STANCE FUNCTIONS ]----------------------------------------------
  2492.  
  2493. function Stand(onDeselected)
  2494.     local LHip = Torso["Left Hip"]
  2495.     local RHip = Torso["Right Hip"]
  2496.     LLegWeld.Part1 = nil
  2497.     LHip.Part1 = LLeg
  2498.     RLegWeld.Part1 = nil
  2499.     RHip.Part1 = RLeg
  2500.     Stance = 0
  2501.     spreadStance = "Stand"
  2502.     baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
  2503.     if S.stanceSettings.Anim and (not onDeselected) then
  2504.         spawn(function()
  2505.             local prevStanceSway = stanceSway
  2506.             local X = 0
  2507.             local Increment = 1.5 / S.stanceSettings.Speed
  2508.             while true do
  2509.                 RS.RenderStepped:wait()
  2510.                 local newX = X + Increment
  2511.                 X = (newX > 90 and 90 or newX)
  2512.                 if Stance ~= 0 then break end
  2513.                 stanceSway = numLerp(prevStanceSway, 1, Sine(X))
  2514.                 if X == 90 then break end
  2515.             end
  2516.         end)
  2517.         tweenJoint(ABWeld, CF(), nil, Sine, S.stanceSettings.Speed)
  2518.         tweenJoint(LLegWeld, legC0.Stand[1], nil, Sine, S.stanceSettings.Speed)
  2519.         tweenJoint(RLegWeld, legC0.Stand[2], nil, Sine, S.stanceSettings.Speed)
  2520.         tweenJoint(LHip, CF(-1, -1, 0) * CFANG(0, RAD(-90), 0), CF(-0.5, 1, 0) * CFANG(0, RAD(-90), 0), Sine, S.stanceSettings.Speed)
  2521.         tweenJoint(RHip, CF(1, -1, 0) * CFANG(RAD(-180), RAD(90), 0), CF(0.5, 1, 0) * CFANG(RAD(-180), RAD(90), 0), Sine, S.stanceSettings.Speed)
  2522.         tweenJoint(Root, CFANG(RAD(-90), 0, RAD(180)), nil, Sine, S.stanceSettings.Speed)
  2523.         tweenJoint(headWeld, CF(0, 1.5, 0), nil, Sine, S.stanceSettings.Speed)
  2524.     elseif onDeselected or (not S.stanceSettings.Anim) then
  2525.         ABWeld.C0 = CF()
  2526.         LLegWeld.C0 = legC0.Stand[1]
  2527.         RLegWeld.C0 = legC0.Stand[2]
  2528.         LHip.C0, LHip.C1 = CF(-1, -1, 0) * CFANG(0, RAD(-90), 0), CF(-0.5, 1, 0) * CFANG(0, RAD(-90), 0)
  2529.         RHip.C0, RHip.C1 = CF(1, -1, 0) * CFANG(RAD(-180), RAD(90), 0), CF(0.5, 1, 0) * CFANG(RAD(-180), RAD(90), 0)
  2530.         Root.C0 = CFANG(RAD(-90), 0, RAD(180))
  2531.         headWeld.C0 = CF(0, 1.5, 0)
  2532.     end
  2533. end
  2534.  
  2535. function Crouch()
  2536.     local LHip = Torso["Left Hip"]
  2537.     local RHip = Torso["Right Hip"]
  2538.     LHip.Part1 = nil
  2539.     LLegWeld.Part1 = LLeg
  2540.     RHip.Part1 = nil
  2541.     RLegWeld.Part1 = RLeg
  2542.     Stance = 1
  2543.     spreadStance = "Crouch"
  2544.     baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
  2545.     if S.stanceSettings.Anim then
  2546.         spawn(function()
  2547.             local prevStanceSway = stanceSway
  2548.             local X = 0
  2549.             local Increment = 1.5 / S.stanceSettings.Speed
  2550.             while true do
  2551.                 RS.RenderStepped:wait()
  2552.                 local newX = X + Increment
  2553.                 X = (newX > 90 and 90 or newX)
  2554.                 if Stance ~= 1 then break end
  2555.                 stanceSway = numLerp(prevStanceSway, 0.75, Sine(X))
  2556.                 if X == 90 then break end
  2557.             end
  2558.         end)
  2559.         tweenJoint(ABWeld, CF(0, 0, -0.05), nil, Sine, S.stanceSettings.Speed)
  2560.         tweenJoint(LLegWeld, legC0.Crouch[1], nil, Sine, S.stanceSettings.Speed)
  2561.         tweenJoint(RLegWeld, legC0.Crouch[2], nil, Sine, S.stanceSettings.Speed)
  2562.         tweenJoint(LHip, CF(-1, -0.5, 0) * CFANG(0, RAD(-90), 0), CF(-0.5, 0.5, 1) * CFANG(0, RAD(-90), RAD(-90)), Sine, S.stanceSettings.Speed)
  2563.         tweenJoint(RHip, CF(1, -0.5, 0.25) * CFANG(RAD(-180), RAD(90), 0), CF(0.5, 0.5, 1) * CFANG(RAD(-180), RAD(90), 0), Sine, S.stanceSettings.Speed)
  2564.         tweenJoint(Root, CF(0, -1, 0) * CFANG(RAD(-90), 0, RAD(180)), nil, Sine, S.stanceSettings.Speed)
  2565.         tweenJoint(headWeld, CF(0, 1.5, 0), nil, Sine, S.stanceSettings.Speed)
  2566.     else
  2567.         ABWeld.C0 = CF(0, 0, -1 / 16)
  2568.         LLegWeld.C0 = legC0.Crouch[1]
  2569.         RLegWeld.C0 = legC0.Crouch[2]
  2570.         LHip.C0, LHip.C1 = CF(-1, -0.5, 0) * CFANG(0, RAD(-90), 0), CF(-0.5, 0.5, 1) * CFANG(0, RAD(-90), RAD(-90))
  2571.         RHip.C0, RHip.C1 = CF(1, -0.5, 0.25) * CFANG(RAD(-180), RAD(90), 0), CF(0.5, 0.5, 1) * CFANG(RAD(-180), RAD(90), 0)
  2572.         Root.C0 = CF(0, -1, 0) * CFANG(RAD(-90), 0, RAD(180))
  2573.         headWeld.C0 = CF(0, 1.5, 0)
  2574.     end
  2575. end
  2576.  
  2577. function Prone()
  2578.     local LHip = Torso["Left Hip"]
  2579.     local RHip = Torso["Right Hip"]
  2580.     LHip.Part1 = nil
  2581.     LLegWeld.Part1 = LLeg
  2582.     RHip.Part1 = nil
  2583.     RLegWeld.Part1 = RLeg
  2584.     Stance = 2
  2585.     spreadStance = "Prone"
  2586.     baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
  2587.     if S.stanceSettings.Anim then
  2588.         spawn(function()
  2589.             local prevStanceSway = stanceSway
  2590.             local X = 0
  2591.             local Increment = 1.5 / S.stanceSettings.Speed
  2592.             while true do
  2593.                 RS.RenderStepped:wait()
  2594.                 local newX = X + Increment
  2595.                 X = (newX > 90 and 90 or newX)
  2596.                 if Stance ~= 2 then break end
  2597.                 stanceSway = numLerp(prevStanceSway, 0.5, Sine(X))
  2598.                 if X == 90 then break end
  2599.             end
  2600.         end)
  2601.         tweenJoint(ABWeld, CF(0, 0, -0.1), nil, Sine, S.stanceSettings.Speed)
  2602.         tweenJoint(LLegWeld, legC0.Prone[1], nil, Sine, S.stanceSettings.Speed)
  2603.         tweenJoint(RLegWeld, legC0.Prone[2], nil, Sine, S.stanceSettings.Speed)
  2604.         tweenJoint(Root, CF(0, -2.5, 1) * CFANG(RAD(180), 0, RAD(180)), nil, Sine, S.stanceSettings.Speed)
  2605.         tweenJoint(headWeld, CF(0, 1, 1) * CFANG(RAD(90), 0, 0), nil, Sine, S.stanceSettings.Speed)
  2606.     else
  2607.         ABWeld.C0 = CF(0, 0, -1 / 8)
  2608.         LLegWeld.C0 = legC0.Prone[1]
  2609.         RLegWeld.C0 = legC0.Prone[2]
  2610.         Root.C0 = CF(0, -2.5, 1) * CFANG(RAD(180), 0, RAD(180))
  2611.         headWeld.C0 = CF(0, 1, 1) * CFANG(RAD(90), 0, 0)
  2612.     end
  2613. end
  2614.  
  2615. function Dive()
  2616.     onGround = false
  2617.     local diveDirection = (HRP.CFrame * CFANG(S.diveSettings.Angle, 0, 0)).lookVector * S.walkSpeeds.Sprinting * S.diveSettings.Force
  2618.     local BF = Instance.new("BodyForce")
  2619.     BF.force = diveDirection + Vector3.new(0, playerMass * 196.2, 0)
  2620.     BF.Parent = HRP
  2621.     --[[spawn(function()
  2622.         HRP.Velocity = HRP.CFrame.lookVector * 60 + V3(0, 40, 0)
  2623.         wait(0.1)
  2624.         HRP.Velocity = HRP.CFrame.lookVector * 70 + V3(0, 30, 0)
  2625.         wait(0.4)
  2626.         HRP.Velocity = HRP.CFrame.lookVector * 30 + V3(0, -10, 0)
  2627.     end)]]
  2628.     delay(0.05, function()
  2629.         spawn(function()
  2630.             while true do
  2631.                 local newRay = Ray.new(HRP.Position, V3(0, -3.1, 0))
  2632.                 local H, _ = workspace:FindPartOnRayWithIgnoreList(newRay, Ignore)
  2633.                 if H then
  2634.                     onGround = true
  2635.                     break
  2636.                 end
  2637.                 wait()
  2638.             end
  2639.         end)
  2640.         Prone()
  2641.         wait(0.1)
  2642.         BF:Destroy()
  2643.     end)
  2644. end
  2645.  
  2646. --------------------[ MOUSE FUNCTIONS ]-----------------------------------------------
  2647.  
  2648. function onMB1Down()
  2649.     MB1Down = true
  2650.     firstShot = true
  2651.     if fireFunction then
  2652.         fireFunction()
  2653.     end
  2654. end
  2655.  
  2656. function onMB1Up()
  2657.     MB1Down = false
  2658.     lowerSpread()
  2659. end
  2660.  
  2661. function onMB2Down()
  2662.     if S.aimSettings.holdToADS then
  2663.         if (not AimingIn) and (not Aimed) then
  2664.             AimingIn = true
  2665.             aimGun()
  2666.             AimingIn = false
  2667.         end
  2668.     else
  2669.         if Aimed then
  2670.             unAimGun()
  2671.         else
  2672.             aimGun()
  2673.         end
  2674.     end
  2675. end
  2676.  
  2677. function onMB2Up()
  2678.     if S.aimSettings.holdToADS then
  2679.         if (not AimingOut) and Aimed then
  2680.             AimingOut = true
  2681.             unAimGun()
  2682.             AimingOut = false
  2683.         end
  2684.     end
  2685. end
  2686.  
  2687. function onScrollUp()
  2688.     local newAimSensitivity = aimSensitivity + S.sensitivitySettings.Increment
  2689.     aimSensitivity = (
  2690.         newAimSensitivity < S.sensitivitySettings.Min and S.sensitivitySettings.Min or
  2691.         newAimSensitivity > S.sensitivitySettings.Max and S.sensitivitySettings.Max or
  2692.         newAimSensitivity
  2693.     )
  2694.     mouseSensitivity = (Aimed and aimSensitivity or mouseSensitivity)
  2695.    
  2696.     Sens.Text = "S: "..aimSensitivity
  2697.     if mainGUI:IsDescendantOf(game) then
  2698.         Sens.Visible = true
  2699.         local t0 = tick()
  2700.         lastSensUpdate = t0
  2701.        
  2702.         wait(0.3)
  2703.        
  2704.         if lastSensUpdate <= t0 then
  2705.             Sens.Visible = false
  2706.         end
  2707.     end
  2708. end
  2709.  
  2710. function onScrollDown()
  2711.     local newAimSensitivity = aimSensitivity - S.sensitivitySettings.Increment
  2712.     aimSensitivity = (
  2713.         newAimSensitivity < S.sensitivitySettings.Min and S.sensitivitySettings.Min or
  2714.         newAimSensitivity > S.sensitivitySettings.Max and S.sensitivitySettings.Max or
  2715.         newAimSensitivity
  2716.     )
  2717.     mouseSensitivity = (Aimed and aimSensitivity or mouseSensitivity)
  2718.    
  2719.     Sens.Text = "S: "..aimSensitivity
  2720.     if mainGUI:IsDescendantOf(game) then
  2721.         Sens.Visible = true
  2722.         local t0 = tick()
  2723.         lastSensUpdate = t0
  2724.        
  2725.         wait(0.3)
  2726.        
  2727.         if lastSensUpdate <= t0 then
  2728.             Sens.Visible = false
  2729.         end
  2730.     end
  2731. end
  2732.  
  2733. --------------------[ KEYBOARD FUNCTIONS ]--------------------------------------------
  2734.  
  2735. function keyDown(K)
  2736.     local Key = string.lower(K)
  2737.    
  2738.     if Key == S.Keys.lowerStance and S.canChangeStance then
  2739.         if (not Running) then
  2740.             if Stance == 0 then
  2741.                 if S.stanceSettings.Stances.Crouch then
  2742.                     Crouch()
  2743.                 elseif S.stanceSettings.Stances.Prone then
  2744.                     Prone()
  2745.                 end
  2746.             elseif Stance == 1 then
  2747.                 if S.stanceSettings.Stances.Prone then
  2748.                     Prone()
  2749.                 end
  2750.             end
  2751.         elseif S.dolphinDive then
  2752.             wait()
  2753.             if Humanoid:GetState() ~= Enum.HumanoidStateType.Freefall and (not UIS:IsKeyDown("Space")) and runReady then
  2754.                 local tempConnection = Humanoid.Changed:connect(function()
  2755.                     Humanoid.Jump = false
  2756.                 end)
  2757.                 runReady = false
  2758.                 Dive()
  2759.                 Running = false
  2760.                 wait(S.diveSettings.rechargeTime)
  2761.                 tempConnection:disconnect()
  2762.                 runReady = true
  2763.             end
  2764.         end
  2765.     end
  2766.    
  2767.     if Key == S.Keys.raiseStance and S.canChangeStance then
  2768.         if (not Running) then
  2769.             if Stance == 2 then
  2770.                 if S.stanceSettings.Stances.Crouch then
  2771.                     Crouch()
  2772.                 else
  2773.                     Stand()
  2774.                 end
  2775.             elseif Stance == 1 then
  2776.                 Stand()
  2777.             end
  2778.         end
  2779.     end
  2780.    
  2781.     if Key == S.Keys.ADS then
  2782.         if S.aimSettings.holdToADS then
  2783.             if (not AimingIn) and (not Aimed) then
  2784.                 AimingIn = true
  2785.                 aimGun()
  2786.                 AimingIn = false
  2787.             end
  2788.         else
  2789.             if Aimed then
  2790.                 unAimGun()
  2791.             else
  2792.                 aimGun()
  2793.             end
  2794.         end
  2795.     end
  2796.    
  2797.     if Key == S.Keys.selectFire and S.selectFire then
  2798.         if canSelectFire then
  2799.             canSelectFire = false
  2800.             rawFireMode = rawFireMode + 1
  2801.             modeGUI.Text = Modes[((rawFireMode - 1) % numModes) + 1]
  2802.             if modeGUI.Text == "AUTO" then
  2803.                 fireFunction = autoFire
  2804.             elseif modeGUI.Text == "BURST" then
  2805.                 fireFunction = burstFire
  2806.             elseif modeGUI.Text == "SEMI" then
  2807.                 fireFunction = semiFire
  2808.             else
  2809.                 fireFunction = nil
  2810.             end
  2811.             local speedAlpha = S.selectFireSettings.animSpeed / 0.6
  2812.             if S.selectFireSettings.GUI then
  2813.                 spawn(function()
  2814.                     fireSelect.Visible = true
  2815.                     local prevRawFireMode = rawFireMode
  2816.                     local Increment = 1.5 / (speedAlpha * 0.25)
  2817.                     local X = 0
  2818.                     wait(speedAlpha * 0.1)
  2819.                     while true do
  2820.                         RS.RenderStepped:wait()
  2821.                         local newX = X + Increment
  2822.                         X = (newX > 90 and 90 or newX)
  2823.                         if prevRawFireMode ~= rawFireMode then break end
  2824.                         updateModeLabels(rawFireMode - 1, rawFireMode, X)
  2825.                         if X == 90 then break end
  2826.                     end
  2827.                     wait(speedAlpha * 0.25)
  2828.                     fireSelect.Visible = false
  2829.                 end)
  2830.             end
  2831.             if S.selectFireSettings.Animation and (not Aimed) and (not isRunning) and (not isCrawling) then
  2832.                 spawn(function()
  2833.                     local sequenceTable = {
  2834.                         function()
  2835.                             tweenJoint(RWeld2, nil, CFANG(0, RAD(5), 0), Sine, speedAlpha * 0.15)
  2836.                             tweenJoint(LWeld, armC0[1], CF(0.1, 1, -0.3) * CFANG(RAD(-7), 0, RAD(-65)), Linear, speedAlpha * 0.15)
  2837.                             wait(speedAlpha * 0.2)
  2838.                         end;
  2839.                        
  2840.                         function()
  2841.                             tweenJoint(LWeld, armC0[1], CF(0.1, 1, -0.3) * CFANG(RAD(-10), 0, RAD(-65)), Linear, speedAlpha * 0.1)
  2842.                             wait(speedAlpha * 0.2)
  2843.                         end;
  2844.                        
  2845.                         function()
  2846.                             tweenJoint(RWeld2, nil, CF(), Sine, speedAlpha * 0.2)
  2847.                             tweenJoint(LWeld, armC0[1], S.unAimedC1.leftArm, Sine, speedAlpha * 0.2)
  2848.                             wait(speedAlpha * 0.2)
  2849.                         end;
  2850.                     }
  2851.                    
  2852.                     for _, F in pairs(sequenceTable) do
  2853.                         if Aimed or isRunning or isCrawling or Reloading then
  2854.                             break
  2855.                         end
  2856.                         F()
  2857.                     end
  2858.                 end)
  2859.             end
  2860.             if S.selectFireSettings.Animation or S.selectFireSettings.GUI then
  2861.                 wait(S.selectFireSettings.animSpeed)
  2862.             end
  2863.             canSelectFire = true
  2864.         end
  2865.     end
  2866.    
  2867.     if Key == S.Keys.Reload then
  2868.         if (not Reloading) and (not isCrawling) then
  2869.             Reload()
  2870.         end
  2871.     end
  2872.    
  2873.     if Key == S.Keys.Sprint then
  2874.         runKeyPressed = true
  2875.         if runReady then
  2876.             if (not Idling) and Walking and (not Running) and (not Knifing) and (not (Aimed and S.guiScope and S.Keys.Sprint == S.Keys.scopeSteady)) then
  2877.                 monitorStamina()
  2878.             end
  2879.         end
  2880.     end
  2881.    
  2882.     if Key == S.Keys.scopeSteady then
  2883.         steadyKeyPressed = true
  2884.         if Aimed and (not Aiming) then
  2885.             takingBreath = false
  2886.             steadyCamera()
  2887.         end
  2888.     end
  2889.    
  2890.     for _, PTable in pairs(Plugins.KeyDown) do
  2891.         if Key == string.lower(PTable.Key) then
  2892.             spawn(function()
  2893.                 PTable.Plugin()
  2894.             end)
  2895.         end
  2896.     end
  2897. end
  2898.  
  2899. function keyUp(K)
  2900.     local Key = string.lower(K)
  2901.    
  2902.     if Key == S.Keys.ADS then
  2903.         if S.aimSettings.holdToADS then
  2904.             if (not AimingOut) and Aimed then
  2905.                 AimingOut = true
  2906.                 unAimGun()
  2907.                 AimingOut = false
  2908.             end
  2909.         end
  2910.     end
  2911.    
  2912.     if Key == S.Keys.Sprint then
  2913.         runKeyPressed = false
  2914.         Running = false
  2915.         if (not chargingStamina) then
  2916.             rechargeStamina()
  2917.         end
  2918.     end
  2919.    
  2920.     if Key == S.Keys.scopeSteady then
  2921.         steadyKeyPressed = false
  2922.     end
  2923.    
  2924.     for _, PTable in pairs(Plugins.KeyUp) do
  2925.         if Key == string.lower(PTable.Key) then
  2926.             spawn(function()
  2927.                 PTable.Plugin()
  2928.             end)
  2929.         end
  2930.     end
  2931. end
  2932.  
  2933. --------------------[ END FUNCTIONS ]-------------------------------------------------
  2934.  
  2935. --------------------------------------------------------------------------------------
  2936. --------------------[ PRE-CONNECTIONS ]-----------------------------------------------
  2937. --------------------------------------------------------------------------------------
  2938.  
  2939. local function updateAnimVars()
  2940.     wait()
  2941.     Forward = (UIS:IsKeyDown("W") or UIS:IsKeyDown("Up"))
  2942.     Backward = (UIS:IsKeyDown("S") or UIS:IsKeyDown("Down"))
  2943.     local Right = UIS:IsKeyDown("D")
  2944.     local Left = UIS:IsKeyDown("A")
  2945.    
  2946.     local walkingForward = (Forward and (not Backward))
  2947.     local walkingBackward = ((not Forward) and Backward)
  2948.     local walkingRight = (Right and (not Left))
  2949.     local walkingLeft = ((not Right) and Left)
  2950.    
  2951.     if (Forward or Backward or Right or Left) then
  2952.         Walking, Idling = true, false
  2953.         if (not Running) and (not Aimed) then
  2954.             spreadMotion = "Moving"
  2955.             baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
  2956.         end
  2957.     elseif (not (Forward and Backward and Right and Left)) then
  2958.         Walking, Idling = false, true
  2959.         if (not Aimed) then
  2960.             spreadMotion = "Idling"
  2961.             baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
  2962.         end
  2963.     end
  2964.    
  2965.     local newArmTilt = (
  2966.         ((walkingForward or walkingBackward) and walkingRight) and 2.5 or
  2967.         ((walkingForward or walkingBackward) and walkingLeft) and -2.5 or
  2968.         ((not (walkingForward and walkingBackward)) and walkingRight) and 5 or
  2969.         ((not (walkingForward and walkingBackward)) and walkingLeft) and -5 or 0
  2970.     )
  2971.     local newMoveAng = (
  2972.         (walkingForward and (not (walkingRight or walkingLeft))) and 0 or
  2973.         (walkingForward and walkingRight) and RAD(-45) or
  2974.         ((not (walkingForward or walkingBackward)) and walkingRight) and RAD(-90) or
  2975.         (walkingBackward and walkingRight) and RAD(-135) or
  2976.         (walkingBackward and (not (walkingRight or walkingLeft))) and (moveAng < 0 and RAD(-180) or RAD(180)) or
  2977.         (walkingBackward and walkingLeft) and RAD(135) or
  2978.         ((not (walkingForward or walkingBackward)) and walkingLeft) and RAD(90) or
  2979.         (walkingForward and walkingLeft) and RAD(45) or 0
  2980.     )
  2981.    
  2982.     local newAnimCode = math.random(-1e9, 1e9)
  2983.     animCode = newAnimCode
  2984.     local startTilt = armTilt
  2985.     local startAng = (ABS(moveAng) == RAD(180)) and (newMoveAng > 0 and RAD(180) or RAD(-180)) or moveAng
  2986.     local Increment = (startTilt == newArmTilt and 1.5 / 0.7 or 1.5 / (0.35 * ABS(startTilt - newArmTilt) / 5))
  2987.     local X = 0
  2988.     while true do
  2989.         RS.RenderStepped:wait()
  2990.         local newX = X + Increment
  2991.         X = (newX > 90 and 90 or newX)
  2992.         if animCode ~= newAnimCode then break end
  2993.         armTilt = numLerp(startTilt, newArmTilt, Sine(X))
  2994.         moveAng = numLerp(startAng, newMoveAng, Sine(X))
  2995.         if X == 90 then break end
  2996.     end
  2997. end
  2998.  
  2999. M2.KeyDown:connect(updateAnimVars)
  3000. M2.KeyUp:connect(updateAnimVars)
  3001. updateAnimVars()
  3002.  
  3003. --------------------------------------------------------------------------------------
  3004. --------------------[ TOOL SELECTION AND DESELECTION ]--------------------------------
  3005. --------------------------------------------------------------------------------------
  3006.  
  3007. function onEquipped()
  3008.     wait()
  3009.     if Humanoid.Health ~= 0 and (not Selected) and Gun.Parent == Char then
  3010.         Selected = true
  3011.         breakReload = false
  3012.         equipAnimPlaying = true
  3013.        
  3014.         math.randomseed(tick()) --This sets a new seed for the random function each time you select the gun
  3015.        
  3016.         --------------------[ FAILSAFE RESETING ]-------------------------------------
  3017.        
  3018.         for _, GM in pairs(ignoreModel:GetChildren()) do
  3019.             if GM.Name == "gunIgnore_"..Player.Name then
  3020.                 GM:Destroy()
  3021.             end
  3022.         end
  3023.        
  3024.         for _, c in pairs(Connections) do
  3025.             c:disconnect()
  3026.         end
  3027.        
  3028.         Connections = {}
  3029.        
  3030.         --------------------[ REMOTE GUN SETUP ]--------------------------------------
  3031.        
  3032.         --[[local Vars = {
  3033.             ignoreModel = ignoreModel;
  3034.             Humanoid = Humanoid;
  3035.             Shoulders = Shoulders;
  3036.             Torso = Torso;
  3037.             Head = Head;
  3038.             armC0 = armC0;
  3039.             leftArmC1 = S.equipSettings.leftArmC1;
  3040.             rightArmC1 = S.equipSettings.rightArmC1;
  3041.             LArm = LArm;
  3042.             RArm = RArm;
  3043.             gunParts = gunParts;
  3044.             Handle = Handle;
  3045.         }
  3046.         gunIgnore, playerFolder, headWeld, headWeld2, animWeld, ABWeld, LWeld, RWeld, LWeld2, RWeld2, LLegWeld, RLegWeld, gunParts2 = gunSetup:InvokeServer(Vars)]]
  3047.        
  3048.         --------------------[ CREATING IGNORE MODELS ]--------------------------------
  3049.        
  3050.         gunIgnore = Instance.new("Model")
  3051.         gunIgnore.Name = "gunIgnore_"..Player.Name
  3052.         gunIgnore.Parent = ignoreModel
  3053.        
  3054.         --------------------[ MODIFYING THE PLAYER ]----------------------------------
  3055.        
  3056.         Player.CameraMode = Enum.CameraMode.LockFirstPerson
  3057.         Cam.CameraType = Enum.CameraType.Scriptable
  3058.         Cam.FieldOfView = 80
  3059.         UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
  3060.         UIS.MouseIconEnabled = false
  3061.        
  3062.         local initialX, initialY = getYawPitch(Cam.CoordinateFrame)
  3063.         camAng = -VEC2(initialX, initialY)
  3064.        
  3065.         mainGUI.Parent = Player.PlayerGui
  3066.        
  3067.         setUpGUI()
  3068.         updateHealth()
  3069.        
  3070.         if S.selectFire then
  3071.             local currentMode = Modes[((rawFireMode - 1) % numModes) + 1]
  3072.             if currentMode == "AUTO" then
  3073.                 fireFunction = autoFire
  3074.             elseif currentMode == "BURST" then
  3075.                 fireFunction = burstFire
  3076.             elseif currentMode == "SEMI" then
  3077.                 fireFunction = semiFire
  3078.             else
  3079.                 fireFunction = nil
  3080.             end
  3081.         else
  3082.             if S.gunType.Semi then
  3083.                 fireFunction = semiFire
  3084.             elseif S.gunType.Auto then
  3085.                 fireFunction = autoFire
  3086.             elseif S.gunType.Burst then
  3087.                 fireFunction = burstFire
  3088.             else
  3089.                 fireFunction = nil
  3090.             end
  3091.         end
  3092.        
  3093.         changePlayerTrans(Char, 1)
  3094.        
  3095.         Humanoid.AutoRotate = false
  3096.        
  3097.         Shoulders.Right.Part1 = nil
  3098.         Shoulders.Left.Part1 = nil
  3099.  
  3100.         playerFolder = Instance.new("Model")
  3101.         playerFolder.Name = "playerFolder"
  3102.         playerFolder.Parent = gunIgnore
  3103.        
  3104.         local headBase = Instance.new("Part")
  3105.         headBase.Transparency = 1
  3106.         headBase.Name = "headBase"
  3107.         headBase.CanCollide = false
  3108.         headBase.FormFactor = Enum.FormFactor.Custom
  3109.         headBase.Size = V3(0.2, 0.2, 0.2)
  3110.         headBase.BottomSurface = Enum.SurfaceType.Smooth
  3111.         headBase.TopSurface = Enum.SurfaceType.Smooth
  3112.         headBase.Parent = playerFolder
  3113.        
  3114.         headWeld = Instance.new("Weld")
  3115.         headWeld.Part0 = Torso
  3116.         headWeld.Part1 = headBase
  3117.         headWeld.C0 = CF(0, 1.5, 0)
  3118.         headWeld.Parent = Torso
  3119.        
  3120.         headWeld2 = Instance.new("Weld")
  3121.         headWeld2.Part0 = headBase
  3122.         headWeld2.Part1 = Head
  3123.         headWeld2.Parent = headBase
  3124.        
  3125.         neckClone = Neck:Clone()
  3126.        
  3127.         --[[local stanceBase = Instance.new("Part")
  3128.         stanceBase.Transparency = 1
  3129.         stanceBase.Name = "stanceBase"
  3130.         stanceBase.CanCollide = false
  3131.         stanceBase.FormFactor = Enum.FormFactor.Custom
  3132.         stanceBase.Size = V3(0.2, 0.2, 0.2)
  3133.         stanceBase.BottomSurface = Enum.SurfaceType.Smooth
  3134.         stanceBase.TopSurface = Enum.SurfaceType.Smooth
  3135.         stanceBase.Parent = playerFolder
  3136.        
  3137.         stanceWeld = Instance.new("Weld")
  3138.         stanceWeld.Part0 = stanceBase
  3139.         stanceWeld.Part1 = Torso
  3140.         stanceWeld.Parent = stanceBase]]
  3141.        
  3142.         local animBase = Instance.new("Part")
  3143.         animBase.Transparency = 1
  3144.         animBase.Name = "animBase"
  3145.         animBase.CanCollide = false
  3146.         animBase.FormFactor = Enum.FormFactor.Custom
  3147.         animBase.Size = V3(0.2, 0.2, 0.2)
  3148.         animBase.BottomSurface = Enum.SurfaceType.Smooth
  3149.         animBase.TopSurface = Enum.SurfaceType.Smooth
  3150.         animBase.Parent = playerFolder
  3151.        
  3152.         animWeld = Instance.new("Weld")
  3153.         animWeld.Part0 = animBase
  3154.         animWeld.Part1 = headBase
  3155.         animWeld.Parent = animBase
  3156.        
  3157.         local ArmBase = Instance.new("Part")
  3158.         ArmBase.Transparency = 1
  3159.         ArmBase.Name = "ArmBase"
  3160.         ArmBase.CanCollide = false
  3161.         ArmBase.FormFactor = Enum.FormFactor.Custom
  3162.         ArmBase.Size = V3(0.2, 0.2, 0.2)
  3163.         ArmBase.BottomSurface = Enum.SurfaceType.Smooth
  3164.         ArmBase.TopSurface = Enum.SurfaceType.Smooth
  3165.         ArmBase.Parent = playerFolder
  3166.        
  3167.         ABWeld = Instance.new("Weld")
  3168.         ABWeld.Part0 = ArmBase
  3169.         ABWeld.Part1 = animBase
  3170.         ABWeld.Parent = ArmBase
  3171.        
  3172.         local LArmBase = Instance.new("Part")
  3173.         LArmBase.Transparency = 1
  3174.         LArmBase.Name = "LArmBase"
  3175.         LArmBase.CanCollide = false
  3176.         LArmBase.FormFactor = Enum.FormFactor.Custom
  3177.         LArmBase.Size = V3(0.2, 0.2, 0.2)
  3178.         LArmBase.BottomSurface = Enum.SurfaceType.Smooth
  3179.         LArmBase.TopSurface = Enum.SurfaceType.Smooth
  3180.         LArmBase.Parent = playerFolder
  3181.        
  3182.         local RArmBase = Instance.new("Part")
  3183.         RArmBase.Transparency = 1
  3184.         RArmBase.Name = "RArmBase"
  3185.         RArmBase.CanCollide = false
  3186.         RArmBase.FormFactor = Enum.FormFactor.Custom
  3187.         RArmBase.Size = V3(0.2, 0.2, 0.2)
  3188.         RArmBase.BottomSurface = Enum.SurfaceType.Smooth
  3189.         RArmBase.TopSurface = Enum.SurfaceType.Smooth
  3190.         RArmBase.Parent = playerFolder
  3191.        
  3192.         LWeld = Instance.new("Weld")
  3193.         LWeld.Name = "LWeld"
  3194.         LWeld.Part0 = ArmBase
  3195.         LWeld.Part1 = LArmBase
  3196.         LWeld.C0 = armC0[1]
  3197.         LWeld.C1 = S.equipSettings.leftArmC1
  3198.         LWeld.Parent = ArmBase
  3199.        
  3200.         RWeld = Instance.new("Weld")
  3201.         RWeld.Name = "RWeld"
  3202.         RWeld.Part0 = ArmBase
  3203.         RWeld.Part1 = RArmBase
  3204.         RWeld.C0 = armC0[2]
  3205.         RWeld.C1 = S.equipSettings.rightArmC1
  3206.         RWeld.Parent = ArmBase
  3207.        
  3208.         LWeld2 = Instance.new("Weld")
  3209.         LWeld2.Name = "LWeld"
  3210.         LWeld2.Part0 = LArmBase
  3211.         LWeld2.Part1 = LArm
  3212.         LWeld2.Parent = LArmBase
  3213.        
  3214.         RWeld2 = Instance.new("Weld")
  3215.         RWeld2.Name = "RWeld"
  3216.         RWeld2.Part0 = RArmBase
  3217.         RWeld2.Part1 = RArm
  3218.         RWeld2.Parent = RArmBase
  3219.        
  3220.         LLegWeld = Instance.new("Weld")
  3221.         LLegWeld.Name = "LLegWeld"
  3222.         LLegWeld.Part0 = Torso
  3223.         LLegWeld.Part1 = nil
  3224.         LLegWeld.C0 = CF(-0.5, -2, 0)
  3225.         LLegWeld.Parent = Torso
  3226.        
  3227.         RLegWeld = Instance.new("Weld")
  3228.         RLegWeld.Name = "RLegWeld"
  3229.         RLegWeld.Part0 = Torso
  3230.         RLegWeld.Part1 = nil
  3231.         RLegWeld.C0 = CF(0.5, -2, 0)
  3232.         RLegWeld.Parent = Torso
  3233.        
  3234.         if S.playerArms then
  3235.             armModel = Instance.new("Model", workspace.FilteringEnabled and playerFolder or Cam)
  3236.            
  3237.             fakeLArm = LArm:Clone()
  3238.             fakeLArm.Parent = armModel
  3239.             fakeLArm.Transparency = S.fakeArmSettings.Transparency
  3240.             fakeLArm.CanCollide = false
  3241.             fakeLArm.Size = S.fakeArmSettings.armSize
  3242.             fakeLArm:BreakJoints()
  3243.            
  3244.             --LArm.Transparency = 1
  3245.            
  3246.             local fakeLWeld = Instance.new("Weld")
  3247.             fakeLWeld.Part0 = fakeLArm
  3248.             fakeLWeld.Part1 = LArm
  3249.             fakeLWeld.Parent = fakeLArm
  3250.            
  3251.             fakeRArm = RArm:Clone()
  3252.             fakeRArm.Parent = armModel
  3253.             fakeRArm.Transparency = S.fakeArmSettings.Transparency
  3254.             fakeRArm.CanCollide = false
  3255.             fakeRArm.Size = S.fakeArmSettings.armSize
  3256.             fakeRArm:BreakJoints()
  3257.            
  3258.             --RArm.Transparency = 1
  3259.            
  3260.             local fakeRWeld = Instance.new("Weld")
  3261.             fakeRWeld.Part0 = fakeRArm
  3262.             fakeRWeld.Part1 = RArm
  3263.             fakeRWeld.Parent = fakeRArm
  3264.            
  3265.             Instance.new("Humanoid", armModel)
  3266.            
  3267.             if S.fakeArmSettings.characterMeshes then
  3268.                 for _,Obj in pairs(Char:GetChildren()) do
  3269.                     if Obj:IsA("CharacterMesh") then
  3270.                         Obj:Clone().Parent = armModel
  3271.                     end
  3272.                 end
  3273.             end
  3274.             for _,Obj in pairs(Char:GetChildren()) do
  3275.                 if Obj:IsA("Shirt") then
  3276.                     Obj:Clone().Parent = armModel
  3277.                 end
  3278.             end
  3279.         else
  3280.             armTable = createArms()
  3281.             if workspace.FilteringEnabled then
  3282.                 armTable[1].Model.Parent = playerFolder
  3283.                 armTable[2].Model.Parent = playerFolder
  3284.             else
  3285.                 armTable[1].Model.Parent = Cam--playerFolder
  3286.                 armTable[2].Model.Parent = Cam--playerFolder
  3287.             end
  3288.            
  3289.             fakeLArm = armTable[1].armPart
  3290.            
  3291.             --LArm.Transparency = 1
  3292.            
  3293.             local fakeLWeld = Instance.new("Weld")
  3294.             fakeLWeld.Part0 = fakeLArm
  3295.             fakeLWeld.Part1 = LArm
  3296.             fakeLWeld.Parent = fakeLArm
  3297.            
  3298.             fakeRArm = armTable[2].armPart
  3299.            
  3300.             --RArm.Transparency = 1
  3301.            
  3302.             local fakeRWeld = Instance.new("Weld")
  3303.             fakeRWeld.Part0 = fakeRArm
  3304.             fakeRWeld.Part1 = RArm
  3305.             fakeRWeld.Parent = fakeRArm
  3306.         end
  3307.        
  3308.         --------------------[ MODIFYING THE GUN ]-------------------------------------
  3309.        
  3310.         for _, Tab in pairs(gunParts) do
  3311.             local Weld = Instance.new("Weld")
  3312.             Weld.Name = "MainWeld"
  3313.             Weld.Part0 = Handle
  3314.             Weld.Part1 = Tab.Obj
  3315.             Weld.C0 = Tab.Obj.weldCF.Value
  3316.             Weld.Parent = Handle
  3317.             Tab.Weld = Weld
  3318.         end
  3319.        
  3320.         Grip = RArm:WaitForChild("RightGrip")
  3321.        
  3322.         local handleCF = Torso.CFrame * CF(0, 0.5, 0) * armC0[2] * S.aimedC1.rightArm:inverse() * Grip.C0
  3323.         local handleOffset = AimPart.CFrame:toObjectSpace(Handle.CFrame)
  3324.         aimedGripCF = ((Torso.CFrame * CF(headOffset.X, headOffset.Y, 0)) * handleOffset):toObjectSpace(handleCF)
  3325.        
  3326.         Grip.C1 = S.equipSettings.GripC1
  3327.        
  3328.         --------------------[ RUNNING PLUGINS ]---------------------------------------
  3329.        
  3330.         for _, Plugin in pairs(Plugins.OnEquipped) do
  3331.             spawn(function()
  3332.                 Plugin()
  3333.             end)
  3334.         end
  3335.        
  3336.         --------------------[ GETTING PLAYER MASS ]-----------------------------------
  3337.        
  3338.         local connectedParts = HRP:GetConnectedParts(true)
  3339.         for _, v in pairs(connectedParts) do
  3340.             if v:IsA("BasePart") then
  3341.                 playerMass = playerMass + v:GetMass()
  3342.             end
  3343.         end
  3344.        
  3345.         --------------------[ CONNECTIONS ]-------------------------------------------
  3346.        
  3347.         INSERT(Connections, Humanoid.Died:connect(function()
  3348.             onUnequipped(true)
  3349.         end))
  3350.        
  3351.         INSERT(Connections, Humanoid.Jumping:connect(function()
  3352.             if Stance ~= 0 then
  3353.                 Stand()
  3354.             end
  3355.         end))
  3356.        
  3357.         INSERT(Connections, Humanoid.StateChanged:connect(onHumanoidStateChanged))
  3358.        
  3359.         INSERT(Connections, Humanoid.HealthChanged:connect(updateHealth))
  3360.        
  3361.         INSERT(Connections, M2.Button1Down:connect(onMB1Down))
  3362.        
  3363.         INSERT(Connections, M2.Button1Up:connect(onMB1Up))
  3364.        
  3365.         INSERT(Connections, M2.Button2Down:connect(onMB2Down))
  3366.        
  3367.         INSERT(Connections, M2.Button2Up:connect(onMB2Up))
  3368.        
  3369.         INSERT(Connections, M2.KeyDown:connect(keyDown))
  3370.        
  3371.         INSERT(Connections, M2.KeyUp:connect(keyUp))
  3372.        
  3373.         if S.sensitivitySettings.scrollToChange then
  3374.             INSERT(Connections, M2.WheelForward:connect(onScrollUp))
  3375.             INSERT(Connections, M2.WheelBackward:connect(onScrollDown))
  3376.         end
  3377.        
  3378.         if S.AutoKnife then
  3379.             INSERT(Connections, RS.Stepped:connect(function()
  3380.                 local H, P = AdvRayCast(Head.CFrame.p, Head.CFrame.lookVector, S.AutoKnifeDist, nil)
  3381.                 if H then
  3382.                     local HitHuman = findFirstClass(H.Parent, "Humanoid")
  3383.                     if HitHuman and isEnemy(HitHuman) and HitHuman.Health ~= 0 then
  3384.                         Knife()
  3385.                     end
  3386.                 end
  3387.             end))
  3388.         end
  3389.        
  3390.         INSERT(Connections, UIS.InputChanged:connect(function(inputObj)
  3391.             if inputObj.UserInputType == Enum.UserInputType.MouseMovement then
  3392.                 local rawCamAng = camAng - (VEC2(RAD(inputObj.Delta.x), RAD(inputObj.Delta.y)) * mouseSensitivity * 0.25)
  3393.                 camAng = VEC2(rawCamAng.x, (rawCamAng.y > RAD(80) and RAD(80) or rawCamAng.y < RAD(-80) and RAD(-80) or rawCamAng.y))
  3394.                
  3395.                 desiredXOffset = math.min(math.max(inputObj.Delta.x, -S.momentumSettings.maxInput), S.momentumSettings.maxInput)
  3396.                 desiredYOffset = math.min(math.max(inputObj.Delta.y, -S.momentumSettings.maxInput), S.momentumSettings.maxInput)
  3397.             end
  3398.         end))
  3399.        
  3400.         INSERT(Connections, M2.Idle:connect(function(inputObj)
  3401.             desiredXOffset = 0
  3402.             desiredYOffset = 0
  3403.         end))
  3404.        
  3405.         INSERT(Connections, RS.Stepped:connect(function()
  3406.             if tick() - lastBeat > (Humanoid.Health / 75) then
  3407.                 lastBeat = tick()
  3408.                 HUD.Health.Tray.Beat:TweenPosition(
  3409.                     UDim2.new(0, -21, 0, 0),
  3410.                     Enum.EasingDirection.Out,
  3411.                     Enum.EasingStyle.Linear,
  3412.                     0.7 - ((100 - Humanoid.Health) / 400),
  3413.                     false,
  3414.                     function()
  3415.                         HUD.Health.Tray.Beat.Position = UDim2.new(1, 0, 0, 0)
  3416.                     end
  3417.                 )
  3418.             end
  3419.         end))
  3420.        
  3421.         INSERT(Connections, RS.RenderStepped:connect(function()
  3422.             --Main animation
  3423.             local animC0, animC1 = getAnimCF()
  3424.             animWeld.C0 = animC0
  3425.             animWeld.C1 = animC1
  3426.            
  3427.             --Camera updating
  3428.             renderCamera()
  3429.         end))
  3430.        
  3431.         --------------------[ ANIMATE GUN ]-------------------------------------------
  3432.        
  3433.         tweenJoint(LWeld, nil, S.unAimedC1.leftArm, Sine, S.equipSettings.Time)
  3434.         tweenJoint(RWeld, nil, S.unAimedC1.rightArm, Sine, S.equipSettings.Time)
  3435.         tweenJoint(Grip, nil, S.unAimedC1.Grip, Sine, S.equipSettings.Time)
  3436.         spawn(function()
  3437.             local T = tick()
  3438.             while true do
  3439.                 if tick() - T > S.equipSettings.Time then break end
  3440.                 if (not Selected) then break end
  3441.                 wait()
  3442.             end
  3443.             equipAnimPlaying = false
  3444.         end)
  3445.        
  3446.         Animate()
  3447.     end
  3448. end
  3449.  
  3450. function onUnequipped(deleteTool)
  3451.     if Selected then
  3452.         Selected = false
  3453.        
  3454.         breakReload = true
  3455.        
  3456.         --------------------[ RUNNING PLUGINS ]---------------------------------------
  3457.        
  3458.         for _, Plugin in pairs(Plugins.OnUnEquipped) do
  3459.             spawn(function()
  3460.                 Plugin()
  3461.             end)
  3462.         end
  3463.        
  3464.         --------------------[ MODIFYING THE PLAYER ]----------------------------------
  3465.        
  3466.         Cam.FieldOfView = 70
  3467.         Cam.CameraType = Enum.CameraType.Custom
  3468.        
  3469.         UIS.MouseBehavior = Enum.MouseBehavior.Default
  3470.         UIS.MouseIconEnabled = true
  3471.        
  3472.         Player.CameraMode = Enum.CameraMode.Classic
  3473.        
  3474.         if armTable then
  3475.             armTable[1].Model:Destroy()
  3476.             armTable[2].Model:Destroy()
  3477.         elseif armModel then
  3478.             armModel:Destroy()
  3479.         end
  3480.        
  3481.         LLegWeld:Destroy()
  3482.         RLegWeld:Destroy()
  3483.        
  3484.         changePlayerTrans(Char, 0)
  3485.        
  3486.         mainGUI.Parent = script
  3487.        
  3488.         Shoulders.Right.Part1 = RArm
  3489.         Shoulders.Left.Part1 = LArm
  3490.        
  3491.         neckClone.Parent = Torso
  3492.         headWeld:Destroy()
  3493.        
  3494.         Humanoid.WalkSpeed = 16
  3495.         Humanoid.AutoRotate = true
  3496.        
  3497.         --------------------[ RESETING THE TOOL ]-------------------------------------
  3498.        
  3499.         gunIgnore:Destroy()
  3500.        
  3501.         mouseSensitivity = S.sensitivitySettings.Default
  3502.        
  3503.         MB1Down = false
  3504.        
  3505.         playerMass = 0
  3506.        
  3507.         Aimed = false
  3508.        
  3509.         camOffsets = {
  3510.             guiScope = {
  3511.                 Rot = V3();
  3512.             };
  3513.             Reload = {
  3514.                 Rot = V3();
  3515.                 Code = nil;
  3516.             };
  3517.             Recoil = {
  3518.                 Rot = V3();
  3519.                 Code = nil;
  3520.             };
  3521.         }
  3522.        
  3523.         recoilAnim = {
  3524.             Pos = V3();
  3525.             Rot = V3();
  3526.             Code = nil;
  3527.         }
  3528.  
  3529.         --Setting the aim variables to unaimed
  3530.         spreadZoom = "unAimed"
  3531.         scopeMain.Visible = false
  3532.         scopeSteady.Visible = false
  3533.         aimAlpha = 0
  3534.         aimHeadOffset = 0
  3535.         jumpAnimMultiplier = 1
  3536.         translationDivisor = 7
  3537.         rotationMultiplier = S.momentumSettings.Amplitude.unAimed
  3538.         armTiltMultiplier = 1
  3539.         Scope.BackgroundTransparency = 1
  3540.         if S.guiScope then
  3541.             spawn(function()
  3542.                 for _, Obj in pairs(Gun:GetChildren()) do
  3543.                     if Obj:IsA("BasePart") then
  3544.                         Obj.LocalTransparencyModifier = 0
  3545.                     end
  3546.                 end
  3547.             end)
  3548.         end
  3549.        
  3550.         onGround = true
  3551.        
  3552.         for _, Tab in pairs(gunParts) do
  3553.             Tab.Weld:Destroy()
  3554.             Tab.Weld = nil
  3555.         end
  3556.        
  3557.         for _,c in pairs(Connections) do
  3558.             c:disconnect()
  3559.         end
  3560.        
  3561.         Connections = {}
  3562.        
  3563.         if deleteTool then
  3564.             Cam:ClearAllChildren()
  3565.             Gun:Destroy()
  3566.         end
  3567.        
  3568.         wait() --This is here in case you dolphin dived and deselected the tool instantly
  3569.        
  3570.         if S.stanceSettings.standOnDeselect and Stance ~= 0 then
  3571.             crawlCamRot = 0
  3572.             isCrawling = false
  3573.             stanceSway = 1
  3574.             spreadStance = "Stand"
  3575.             Stand(true)
  3576.         end
  3577.         baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
  3578.     end
  3579. end
  3580.  
  3581. Gun.Equipped:connect(onEquipped)
  3582. Gun.Unequipped:connect(function() onUnequipped(false) end)
  3583.  
  3584. --------------------------------------------------------------------------------------
  3585. --------------------[ END PROGRAM ]---------------------------------------------------
  3586. --------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment