--// Firemode Functions
function CreateBullet(L_199_arg1)
	local L_200_ = L_58_.Position
	local L_201_ = (L_4_.Hit.p - L_200_).unit
	local L_202_ = CFrame.Angles(math.rad(math.random(-L_199_arg1, L_199_arg1)), math.rad(math.random(-L_199_arg1, L_199_arg1)), math.rad(math.random(-L_199_arg1, L_199_arg1)))
	L_201_ = L_202_ * L_201_	
	local L_203_ = CFrame.new(L_200_, L_200_ + L_201_)	
		
	local L_204_ = Instance.new("Part", L_100_)
	game.Debris:AddItem(L_204_, 10)
	L_204_.Shape = Enum.PartType.Ball
	L_204_.Size = Vector3.new(1, 1, 12)
	L_204_.Name = "Bullet"
	L_204_.TopSurface = "Smooth"
	L_204_.BottomSurface = "Smooth"
	L_204_.BrickColor = BrickColor.new("Bright green")
	L_204_.Material = "Neon"
	L_204_.CanCollide = false
		--Bullet.CFrame = FirePart.CFrame + (Grip.CFrame.p - Grip.CFrame.p)
	L_204_.CFrame = L_203_
		
	local L_205_ = Instance.new("Sound")
	L_205_.SoundId = "rbxassetid://341519743"
	L_205_.Looped = true
	L_205_:Play()
	L_205_.Parent = L_204_
	L_205_.Volume = 0.4
	L_205_.MaxDistance = 30
	
	L_204_.Transparency = 1
	local L_206_ = L_204_:GetMass()
	local L_207_ = Instance.new('BodyForce', L_204_)
		
	if not L_82_ then
		L_207_.Force = L_24_.BulletPhysics
		L_204_.Velocity = L_201_ * L_24_.BulletSpeed
	else
		L_207_.Force = L_24_.ExploPhysics
		L_204_.Velocity = L_201_ * L_24_.ExploSpeed
	end
		
	local L_208_ = Instance.new('Attachment', L_204_)
	L_208_.Position = Vector3.new(0.1, 0, 0)
	local L_209_ = Instance.new('Attachment', L_204_)
	L_209_.Position = Vector3.new(-0.1, 0, 0)
			
	local L_210_ = TracerCalculation()
		
	if L_24_.TracerEnabled == true and L_210_ then
		local L_211_ = Instance.new('Trail', L_204_)
		L_211_.Attachment0 = L_208_
		L_211_.Attachment1 = L_209_
		L_211_.Transparency = NumberSequence.new(L_24_.TracerTransparency)
		L_211_.LightEmission = L_24_.TracerLightEmission
		L_211_.TextureLength = L_24_.TracerTextureLength
		L_211_.Lifetime = L_24_.TracerLifetime
		L_211_.FaceCamera = L_24_.TracerFaceCamera
		L_211_.Color = ColorSequence.new(L_24_.TracerColor.Color)
	end
		
	if L_1_:FindFirstChild('Shell') and not L_82_ then	
		CreateShell()	
	end	
		
	delay(0.2, function()
		L_204_.Transparency = 0
	end)
	
	return L_204_
end

function CheckForHumanoid(L_212_arg1)
	local L_213_ = false
	local L_214_ = nil
	if L_212_arg1 then
		if (L_212_arg1.Parent:FindFirstChild("Humanoid") or L_212_arg1.Parent.Parent:FindFirstChild("Humanoid")) then
			L_213_ = true
			if L_212_arg1.Parent:FindFirstChild('Humanoid') then
				L_214_ = L_212_arg1.Parent.Humanoid
			elseif L_212_arg1.Parent.Parent:FindFirstChild('Humanoid') then
				L_214_ = L_212_arg1.Parent.Parent.Humanoid
			end
		else
			L_213_ = false
		end	
	end
	return L_213_, L_214_
end

function CastRay(L_215_arg1)
	local L_216_, L_217_, L_218_
	local L_219_ = L_55_.Position;
	local L_220_ = L_215_arg1.Position;
	local L_221_ = 0

	local L_222_ = L_82_	
	
	while true do
		L_105_:wait()
		L_220_ = L_215_arg1.Position;
		L_221_ = L_221_ + (L_220_ - L_219_).magnitude
		L_216_, L_217_, L_218_ = workspace:FindPartOnRayWithIgnoreList(Ray.new(L_219_, (L_220_ - L_219_)), IgnoreList);
		local L_223_ = Vector3.new(0, 1, 0):Cross(L_218_)
		local L_224_ = math.asin(L_223_.magnitude) -- division by 1 is redundant
		if L_221_ > L_24_.BulletDecay then
			L_215_arg1:Destroy()
			break
		end
		if L_216_ and (L_216_ and L_216_.Transparency >= 1 or L_216_.CanCollide == false) and L_216_.Name ~= 'Right Arm' and L_216_.Name ~= 'Left Arm' and L_216_.Name ~= 'Right Leg' and L_216_.Name ~= 'Left Leg' and L_216_.Name ~= 'Armor' then
			table.insert(IgnoreList, L_216_)
		end
	
		if L_216_ then
			L_223_ = Vector3.new(0, 1, 0):Cross(L_218_)
			L_224_ = math.asin(L_223_.magnitude) -- division by 1 is redundant
		
			L_117_:FireServer(L_217_)
		
			local L_225_ = CheckForHumanoid(L_216_)
			if L_225_ == false then
				L_215_arg1:Destroy()
				local L_226_ = L_112_:InvokeServer(L_217_, L_223_, L_224_, L_218_, "Part", L_216_)
			elseif L_225_ == true then
				L_215_arg1:Destroy()
				local L_227_ = L_112_:InvokeServer(L_217_, L_223_, L_224_, L_218_, "Human", L_216_)
			end
		end
	
		if L_216_ and L_222_ then
			L_115_:FireServer(L_217_)
		end
	
		if L_216_ then
			local L_228_, L_229_ = CheckForHumanoid(L_216_)
			if L_228_ then
				L_110_:FireServer(L_229_)
				if L_24_.AntiTK then
					if game.Players:FindFirstChild(L_229_.Parent.Name) and game.Players:FindFirstChild(L_229_.Parent.Name).TeamColor ~= L_2_.TeamColor or L_229_.Parent:FindFirstChild('Vars') and game.Players:FindFirstChild(L_229_.Parent:WaitForChild('Vars'):WaitForChild('BotID').Value) and L_2_.TeamColor ~= L_229_.Parent:WaitForChild('Vars'):WaitForChild('teamColor').Value then
						if L_216_.Name == 'Head' then
							L_109_:FireServer(L_229_, L_24_.HeadDamage)
							local L_230_ = L_19_:WaitForChild('BodyHit'):clone()
							L_230_.Parent = L_2_.PlayerGui
							L_230_:Play()
							game:GetService("Debris"):addItem(L_230_, L_230_.TimeLength)
						end
						if L_216_.Name ~= 'Head' and not (L_216_.Parent:IsA('Accessory') or L_216_.Parent:IsA('Hat')) then
							if L_216_.Name ~= 'Torso' and L_216_.Name ~= 'HumanoidRootPart' and L_216_.Name ~= 'Armor' then
								L_109_:FireServer(L_229_, L_24_.LimbDamage)
							elseif L_216_.Name == 'Torso' or L_216_.Name == 'HumanoidRootPart' and L_216_.Name ~= 'Armor'  then
								L_109_:FireServer(L_229_, L_24_.BaseDamage)
							elseif L_216_.Name == 'Armor' then
								L_109_:FireServer(L_229_, L_24_.ArmorDamage)
							end
							local L_231_ = L_19_:WaitForChild('BodyHit'):clone()
							L_231_.Parent = L_2_.PlayerGui
							L_231_:Play()
							game:GetService("Debris"):addItem(L_231_, L_231_.TimeLength)
						end
						if (L_216_.Parent:IsA('Accessory') or L_216_.Parent:IsA('Hat')) then
							L_109_:FireServer(L_229_, L_24_.HeadDamage)
							local L_232_ = L_19_:WaitForChild('BodyHit'):clone()
							L_232_.Parent = L_2_.PlayerGui
							L_232_:Play()
							game:GetService("Debris"):addItem(L_232_, L_232_.TimeLength)
						end
					end
				else
					if L_216_.Name == 'Head' then
						L_109_:FireServer(L_229_, L_24_.HeadDamage)
						local L_233_ = L_19_:WaitForChild('BodyHit'):clone()
						L_233_.Parent = L_2_.PlayerGui
						L_233_:Play()
						game:GetService("Debris"):addItem(L_233_, L_233_.TimeLength)
					end
					if L_216_.Name ~= 'Head' and not (L_216_.Parent:IsA('Accessory') or L_216_.Parent:IsA('Hat')) then
						if L_216_.Name ~= 'Torso' and L_216_.Name ~= 'HumanoidRootPart' and L_216_.Name ~= 'Armor' then
							L_109_:FireServer(L_229_, L_24_.LimbDamage)
						elseif L_216_.Name == 'Torso' or L_216_.Name == 'HumanoidRootPart' and L_216_.Name ~= 'Armor' then
							L_109_:FireServer(L_229_, L_24_.BaseDamage)
						elseif L_216_.Name == 'Armor' then
							L_109_:FireServer(L_229_, L_24_.ArmorDamage)
						end
						local L_234_ = L_19_:WaitForChild('BodyHit'):clone()
						L_234_.Parent = L_2_.PlayerGui
						L_234_:Play()
						game:GetService("Debris"):addItem(L_234_, L_234_.TimeLength)
					end
					if (L_216_.Parent:IsA('Accessory') or L_216_.Parent:IsA('Hat')) then
						L_109_:FireServer(L_229_, L_24_.HeadDamage)
						local L_235_ = L_19_:WaitForChild('BodyHit'):clone()
						L_235_.Parent = L_2_.PlayerGui
						L_235_:Play()
						game:GetService("Debris"):addItem(L_235_, L_235_.TimeLength)
					end
				end	
			end
		end
	
		if L_216_ and L_216_.Parent:FindFirstChild("Humanoid") then
			return L_216_, L_217_;
		end
		L_219_ = L_220_;
	end
end

function fireSemi()
	if L_15_ then
		L_68_ = false
		Recoiling = true
		Shooting = true
		
		--CheckReverb()
		if L_54_ then
			L_54_:FireServer(L_58_:WaitForChild('Fire').SoundId, L_58_)
		else
			L_58_:WaitForChild('Fire'):Play()	
		end
		L_108_:FireServer()
		L_101_ = CreateBullet(L_24_.BulletSpread)
		L_102_ = L_102_ - 1
		UpdateAmmo()
		RecoilFront = true
		local L_236_, L_237_ = spawn(function()
			CastRay(L_101_)
		end)
		
		if L_24_.CanBolt == true then
			BoltingBackAnim()
			delay(L_24_.Firerate / 2, function()
				if L_24_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_24_.CanSlideLock == true then
					if L_102_ > 0 then
						BoltingForwardAnim()
					end
				end
			end)
		end
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)		
		
		wait(L_24_.Firerate)
		
		local L_238_ = JamCalculation()
		if L_238_ then
			L_68_ = false
		else
			L_68_ = true
		end
		Shooting = false
	end
end

function fireExplo()
	if L_15_ then
		L_68_ = false
		Recoiling = true
		Shooting = true
		if L_54_ then
			L_54_:FireServer(L_59_:WaitForChild('Fire').SoundId, L_59_)
		else
			L_59_:WaitForChild('Fire'):Play()	
		end
		L_108_:FireServer()
		L_101_ = CreateBullet(L_24_.BulletSpread)
		L_104_ = L_104_ - 1
		UpdateAmmo()
		RecoilFront = true
		local L_239_, L_240_ = spawn(function()
			CastRay(L_101_)
		end)
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)		
			
		L_68_ = false
		Shooting = false
	end
end

function fireShot()
	if L_15_ then
		L_68_ = false
		Recoiling = true
		Shooting = true
		RecoilFront = true
		--CheckReverb()
		if L_54_ then
			L_54_:FireServer(L_58_:WaitForChild('Fire').SoundId, L_58_)
		else
			L_58_:WaitForChild('Fire'):Play()	
		end
		L_108_:FireServer()
		for L_242_forvar1 = 1, L_24_.ShotNum do
			spawn(function()
				L_101_ = CreateBullet(L_24_.BulletSpread)
			end)
			local L_243_, L_244_ = spawn(function()
				CastRay(L_101_)
			end)
		end
						
		for L_245_forvar1, L_246_forvar2 in pairs(L_58_:GetChildren()) do
			if L_246_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_246_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_247_forvar1, L_248_forvar2 in pairs(L_58_:GetChildren()) do
				if L_248_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_248_forvar2.Enabled = false
				end
			end
		end)
		
		if L_24_.CanBolt == true then
			BoltingBackAnim()
			delay(L_24_.Firerate / 2, function()
				if L_24_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_24_.CanSlideLock == true then
					if L_102_ > 0 then
						BoltingForwardAnim()
					end
				end
			end)
		end
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		L_102_ = L_102_ - 1
		UpdateAmmo()
		wait(L_24_.Firerate)
		
		L_75_ = true
		BoltBackAnim()
		BoltForwardAnim()
		IdleAnim()
		L_75_ = false
		
		local L_241_ = JamCalculation()
		if L_241_ then
			L_68_ = false
		else
			L_68_ = true
		end
		
		Shooting = false
	end
end

function fireBoltAction()
	if L_15_ then
		L_68_ = false
		Recoiling = true
		Shooting = true
		--CheckReverb()
		if L_54_ then
			L_54_:FireServer(L_58_:WaitForChild('Fire').SoundId, L_58_)
		else
			L_58_:WaitForChild('Fire'):Play()	
		end
		L_108_:FireServer()
		L_101_ = CreateBullet(L_24_.BulletSpread)
		L_102_ = L_102_ - 1
		UpdateAmmo()
		RecoilFront = true
		local L_249_, L_250_ = spawn(function()
			CastRay(L_101_)
		end)
						
		for L_252_forvar1, L_253_forvar2 in pairs(L_58_:GetChildren()) do
			if L_253_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_253_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_254_forvar1, L_255_forvar2 in pairs(L_58_:GetChildren()) do
				if L_255_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_255_forvar2.Enabled = false
				end
			end
		end)
		
		if L_24_.CanBolt == true then
			BoltingBackAnim()
			delay(L_24_.Firerate / 2, function()
				if L_24_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_24_.CanSlideLock == true then
					if L_102_ > 0 then
						BoltingForwardAnim()
					end
				end
			end)
		end
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		wait(L_24_.Firerate)
		
		L_75_ = true
		BoltBackAnim()
		BoltForwardAnim()
		IdleAnim()
		L_75_ = false
		
		local L_251_ = JamCalculation()
		if L_251_ then
			L_68_ = false
		else
			L_68_ = true
		end		
		
		Shooting = false
	end
end

function fireAuto()
	while not Shooting and L_102_ > 0 and L_67_ and L_68_ and L_15_ do
		L_68_ = false
		Recoiling = true
		--CheckReverb()
		if L_54_ then
			L_54_:FireServer(L_58_:WaitForChild('Fire').SoundId, L_58_)
		else
			L_58_:WaitForChild('Fire'):Play()	
		end
		L_108_:FireServer()
		L_102_ = L_102_ - 1
		UpdateAmmo()
		Shooting = true
		RecoilFront = true
		L_101_ = CreateBullet(L_24_.BulletSpread)
		local L_256_, L_257_ = spawn(function()
			CastRay(L_101_)
		end)
					
		for L_259_forvar1, L_260_forvar2 in pairs(L_58_:GetChildren()) do
			if L_260_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_260_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_261_forvar1, L_262_forvar2 in pairs(L_58_:GetChildren()) do
				if L_262_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_262_forvar2.Enabled = false
				end
			end
		end)
		
		if L_24_.CanBolt == true then
			BoltingBackAnim()
			delay(L_24_.Firerate / 2, function()
				if L_24_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_24_.CanSlideLock == true then
					if L_102_ > 0 then
						BoltingForwardAnim()
					end
				end
			end)
		end
		
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		wait(L_24_.Firerate)
		
		local L_258_ = JamCalculation()
		if L_258_ then
			L_68_ = false
		else
			L_68_ = true
		end
		
		Shooting = false
	end
end

function fireBurst()
	if not Shooting and L_102_ > 0 and L_67_ and L_15_ then
		for L_263_forvar1 = 1, L_24_.BurstNum do
			if L_102_ > 0 and L_67_ then
				L_68_ = false
				Recoiling = true
			--CheckReverb()
				if L_54_ then
					L_54_:FireServer(L_58_:WaitForChild('Fire').SoundId, L_58_)
				else
					L_58_:WaitForChild('Fire'):Play()	
				end
				L_108_:FireServer()
				L_101_ = CreateBullet(L_24_.BulletSpread)
				local L_264_, L_265_ = spawn(function()
					CastRay(L_101_)
				end)
					
				for L_267_forvar1, L_268_forvar2 in pairs(L_58_:GetChildren()) do
					if L_268_forvar2.Name:sub(1, 7) == "FlashFX" then
						L_268_forvar2.Enabled = true
					end
				end
		
				delay(1 / 30, function()
					for L_269_forvar1, L_270_forvar2 in pairs(L_58_:GetChildren()) do
						if L_270_forvar2.Name:sub(1, 7) == "FlashFX" then
							L_270_forvar2.Enabled = false
						end
					end
				end)
			
				if L_24_.CanBolt == true then
					BoltingBackAnim()
					delay(L_24_.Firerate / 2, function()
						if L_24_.CanSlideLock == false then
							BoltingForwardAnim()
						elseif L_24_.CanSlideLock == true then
							if L_102_ > 0 then
								BoltingForwardAnim()
							end
						end
					end)
				end
			
				L_102_ = L_102_ - 1
				UpdateAmmo()
				RecoilFront = true
				delay(L_24_.Firerate / 2, function()
					Recoiling = false
					RecoilFront = false
				end)
				wait(L_24_.Firerate)
			
				local L_266_ = JamCalculation()
				if L_266_ then
					L_68_ = false
				else
					L_68_ = true
				end
		
			end
			Shooting = true
		end
		Shooting = false
	end
end

function Shoot()
	if L_15_ and L_68_ then
		if L_91_ == 1 then
			fireSemi()
		elseif L_91_ == 2 then
			fireAuto()
		elseif L_91_ == 3 then
			fireBurst()	
		elseif L_91_ == 4 then
			fireBoltAction()
		elseif L_91_ == 5 then
			fireShot()
		elseif L_91_ == 6 then
			fireExplo()
		end
	end
end