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

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

function CastRay(L_219_arg1)
	local L_220_, L_221_, L_222_
	local L_223_ = L_56_.Position;
	local L_224_ = L_219_arg1.Position;
	local L_225_ = 0

	local L_226_ = L_83_	
	
	while true do
		L_109_:wait()
		L_224_ = L_219_arg1.Position;
		L_225_ = L_225_ + (L_224_ - L_223_).magnitude
		L_220_, L_221_, L_222_ = workspace:FindPartOnRayWithIgnoreList(Ray.new(L_223_, (L_224_ - L_223_)), IgnoreList);
		local L_227_ = Vector3.new(0, 1, 0):Cross(L_222_)
		local L_228_ = math.asin(L_227_.magnitude) -- division by 1 is redundant
		if L_225_ > L_24_.BulletDecay then
			L_219_arg1:Destroy()
			break
		end
		if L_220_ and (L_220_ and L_220_.Transparency >= 1 or L_220_.CanCollide == false) and L_220_.Name ~= 'Right Arm' and L_220_.Name ~= 'Left Arm' and L_220_.Name ~= 'Right Leg' and L_220_.Name ~= 'Left Leg' and L_220_.Name ~= 'Armor' then
			table.insert(IgnoreList, L_220_)
		end
	
		if L_220_ then
			L_227_ = Vector3.new(0, 1, 0):Cross(L_222_)
			L_228_ = math.asin(L_227_.magnitude) -- division by 1 is redundant
		
			L_121_:FireServer(L_221_)
		
			local L_229_ = CheckForHumanoid(L_220_)
			if L_229_ == false then
				L_219_arg1:Destroy()
				L_116_:FireServer(L_221_, L_227_, L_228_, L_222_, "Part", L_220_)
			elseif L_229_ == true then
				L_219_arg1:Destroy()
				L_116_:FireServer(L_221_, L_227_, L_228_, L_222_, "Human", L_220_)
			end
		end
	
		if L_220_ and L_226_ then
			L_119_:FireServer(L_221_)
		end
	
		if L_220_ then
			local L_230_, L_231_ = CheckForHumanoid(L_220_)
			if L_230_ then
				L_114_:FireServer(L_231_)
				if L_24_.AntiTK then
					if game.Players:FindFirstChild(L_231_.Parent.Name) and game.Players:FindFirstChild(L_231_.Parent.Name).TeamColor ~= L_2_.TeamColor or L_231_.Parent:FindFirstChild('Vars') and game.Players:FindFirstChild(L_231_.Parent:WaitForChild('Vars'):WaitForChild('BotID').Value) and L_2_.TeamColor ~= L_231_.Parent:WaitForChild('Vars'):WaitForChild('teamColor').Value then
						if L_220_.Name == 'Head' then
							L_113_:FireServer(L_231_, 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
						if L_220_.Name ~= 'Head' and not (L_220_.Parent:IsA('Accessory') or L_220_.Parent:IsA('Hat')) then
							if L_220_.Name ~= 'Torso' and L_220_.Name ~= 'HumanoidRootPart' and L_220_.Name ~= 'Armor' then
								L_113_:FireServer(L_231_, L_24_.LimbDamage)
							elseif L_220_.Name == 'Torso' or L_220_.Name == 'HumanoidRootPart' and L_220_.Name ~= 'Armor'  then
								L_113_:FireServer(L_231_, L_24_.BaseDamage)
							elseif L_220_.Name == 'Armor' then
								L_113_:FireServer(L_231_, L_24_.ArmorDamage)
							end
							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_220_.Parent:IsA('Accessory') or L_220_.Parent:IsA('Hat')) then
							L_113_:FireServer(L_231_, L_24_.HeadDamage)
							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
					end
				else
					if L_220_.Name == 'Head' then
						L_113_:FireServer(L_231_, 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
					if L_220_.Name ~= 'Head' and not (L_220_.Parent:IsA('Accessory') or L_220_.Parent:IsA('Hat')) then
						if L_220_.Name ~= 'Torso' and L_220_.Name ~= 'HumanoidRootPart' and L_220_.Name ~= 'Armor' then
							L_113_:FireServer(L_231_, L_24_.LimbDamage)
						elseif L_220_.Name == 'Torso' or L_220_.Name == 'HumanoidRootPart' and L_220_.Name ~= 'Armor' then
							L_113_:FireServer(L_231_, L_24_.BaseDamage)
						elseif L_220_.Name == 'Armor' then
							L_113_:FireServer(L_231_, L_24_.ArmorDamage)
						end
						local L_236_ = L_19_:WaitForChild('BodyHit'):clone()
						L_236_.Parent = L_2_.PlayerGui
						L_236_:Play()
						game:GetService("Debris"):addItem(L_236_, L_236_.TimeLength)
					end
					if (L_220_.Parent:IsA('Accessory') or L_220_.Parent:IsA('Hat')) then
						L_113_:FireServer(L_231_, L_24_.HeadDamage)
						local L_237_ = L_19_:WaitForChild('BodyHit'):clone()
						L_237_.Parent = L_2_.PlayerGui
						L_237_:Play()
						game:GetService("Debris"):addItem(L_237_, L_237_.TimeLength)
					end
				end	
			end
		end
	
		if L_220_ and L_220_.Parent:FindFirstChild("Humanoid") then
			return L_220_, L_221_;
		end
		L_223_ = L_224_;
	end
end

function fireSemi()
	if L_15_ then
		L_69_ = false
		Recoiling = true
		Shooting = true
		
		--CheckReverb()
		if L_54_ then
			L_54_:FireServer(L_59_:WaitForChild('Fire').SoundId, L_59_)
		else
			L_59_:WaitForChild('Fire'):Play()	
		end
		L_112_:FireServer()
		L_105_ = CreateBullet(L_24_.BulletSpread)
		L_106_ = L_106_ - 1
		UpdateAmmo()
		RecoilFront = true
		local L_238_, L_239_ = spawn(function()
			CastRay(L_105_)
		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_106_ > 0 then
						BoltingForwardAnim()
					end
				end
			end)
		end
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)		
		
		wait(L_24_.Firerate)
		
		local L_240_ = JamCalculation()
		if L_240_ then
			L_69_ = false
		else
			L_69_ = true
		end
		Shooting = false
	end
end

function fireExplo()
	if L_15_ then
		L_69_ = false
		Recoiling = true
		Shooting = true
		if L_54_ then
			L_54_:FireServer(L_60_:WaitForChild('Fire').SoundId, L_60_)
		else
			L_60_:WaitForChild('Fire'):Play()	
		end
		L_112_:FireServer()
		L_105_ = CreateBullet(L_24_.BulletSpread)
		L_108_ = L_108_ - 1
		UpdateAmmo()
		RecoilFront = true
		local L_241_, L_242_ = spawn(function()
			CastRay(L_105_)
		end)
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)		
			
		L_69_ = false
		Shooting = false
	end
end

function fireShot()
	if L_15_ then
		L_69_ = false
		Recoiling = true
		Shooting = true
		RecoilFront = true
		--CheckReverb()
		if L_54_ then
			L_54_:FireServer(L_59_:WaitForChild('Fire').SoundId, L_59_)
		else
			L_59_:WaitForChild('Fire'):Play()	
		end
		L_112_:FireServer()
		for L_244_forvar1 = 1, L_24_.ShotNum do
			spawn(function()
				L_105_ = CreateBullet(L_24_.BulletSpread)
			end)
			local L_245_, L_246_ = spawn(function()
				CastRay(L_105_)
			end)
		end
						
		for L_247_forvar1, L_248_forvar2 in pairs(L_59_:GetChildren()) do
			if L_248_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_248_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_249_forvar1, L_250_forvar2 in pairs(L_59_:GetChildren()) do
				if L_250_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_250_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_106_ > 0 then
						BoltingForwardAnim()
					end
				end
			end)
		end
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		L_106_ = L_106_ - 1
		UpdateAmmo()
		wait(L_24_.Firerate)
		
		L_76_ = true
		BoltBackAnim()
		BoltForwardAnim()
		IdleAnim()
		L_76_ = false
		
		local L_243_ = JamCalculation()
		if L_243_ then
			L_69_ = false
		else
			L_69_ = true
		end
		
		Shooting = false
	end
end

function fireBoltAction()
	if L_15_ then
		L_69_ = false
		Recoiling = true
		Shooting = true
		--CheckReverb()
		if L_54_ then
			L_54_:FireServer(L_59_:WaitForChild('Fire').SoundId, L_59_)
		else
			L_59_:WaitForChild('Fire'):Play()	
		end
		L_112_:FireServer()
		L_105_ = CreateBullet(L_24_.BulletSpread)
		L_106_ = L_106_ - 1
		UpdateAmmo()
		RecoilFront = true
		local L_251_, L_252_ = spawn(function()
			CastRay(L_105_)
		end)
						
		for L_254_forvar1, L_255_forvar2 in pairs(L_59_:GetChildren()) do
			if L_255_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_255_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_256_forvar1, L_257_forvar2 in pairs(L_59_:GetChildren()) do
				if L_257_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_257_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_106_ > 0 then
						BoltingForwardAnim()
					end
				end
			end)
		end
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		wait(L_24_.Firerate)
		
		L_76_ = true
		BoltBackAnim()
		BoltForwardAnim()
		IdleAnim()
		L_76_ = false
		
		local L_253_ = JamCalculation()
		if L_253_ then
			L_69_ = false
		else
			L_69_ = true
		end		
		
		Shooting = false
	end
end

function fireAuto()
	while not Shooting and L_106_ > 0 and L_68_ and L_69_ and L_15_ do
		L_69_ = false
		Recoiling = true
		--CheckReverb()
		if L_54_ then
			L_54_:FireServer(L_59_:WaitForChild('Fire').SoundId, L_59_)
		else
			L_59_:WaitForChild('Fire'):Play()	
		end
		L_112_:FireServer()
		L_106_ = L_106_ - 1
		UpdateAmmo()
		Shooting = true
		RecoilFront = true
		L_105_ = CreateBullet(L_24_.BulletSpread)
		local L_258_, L_259_ = spawn(function()
			CastRay(L_105_)
		end)
					
		for L_261_forvar1, L_262_forvar2 in pairs(L_59_:GetChildren()) do
			if L_262_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_262_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_263_forvar1, L_264_forvar2 in pairs(L_59_:GetChildren()) do
				if L_264_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_264_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_106_ > 0 then
						BoltingForwardAnim()
					end
				end
			end)
		end
		
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		wait(L_24_.Firerate)
		
		local L_260_ = JamCalculation()
		if L_260_ then
			L_69_ = false
		else
			L_69_ = true
		end
		
		Shooting = false
	end
end

function fireBurst()
	if not Shooting and L_106_ > 0 and L_68_ and L_15_ then
		for L_265_forvar1 = 1, L_24_.BurstNum do
			if L_106_ > 0 and L_68_ then
				L_69_ = false
				Recoiling = true
			--CheckReverb()
				if L_54_ then
					L_54_:FireServer(L_59_:WaitForChild('Fire').SoundId, L_59_)
				else
					L_59_:WaitForChild('Fire'):Play()	
				end
				L_112_:FireServer()
				L_105_ = CreateBullet(L_24_.BulletSpread)
				local L_266_, L_267_ = spawn(function()
					CastRay(L_105_)
				end)
					
				for L_269_forvar1, L_270_forvar2 in pairs(L_59_:GetChildren()) do
					if L_270_forvar2.Name:sub(1, 7) == "FlashFX" then
						L_270_forvar2.Enabled = true
					end
				end
		
				delay(1 / 30, function()
					for L_271_forvar1, L_272_forvar2 in pairs(L_59_:GetChildren()) do
						if L_272_forvar2.Name:sub(1, 7) == "FlashFX" then
							L_272_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_106_ > 0 then
								BoltingForwardAnim()
							end
						end
					end)
				end
			
				L_106_ = L_106_ - 1
				UpdateAmmo()
				RecoilFront = true
				delay(L_24_.Firerate / 2, function()
					Recoiling = false
					RecoilFront = false
				end)
				wait(L_24_.Firerate)
			
				local L_268_ = JamCalculation()
				if L_268_ then
					L_69_ = false
				else
					L_69_ = true
				end
		
			end
			Shooting = true
		end
		Shooting = false
	end
end

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