--// Firemode Functions
function CreateBullet(L_141_arg1)
	local L_142_ = L_37_.Position
	local L_143_ = (L_4_.Hit.p - L_142_).unit
	local L_144_ = CFrame.Angles(math.rad(math.random(-L_141_arg1, L_141_arg1)), math.rad(math.random(-L_141_arg1, L_141_arg1)), math.rad(math.random(-L_141_arg1, L_141_arg1)))
	L_143_ = L_144_ * L_143_	
	local L_145_ = CFrame.new(L_142_, L_142_ + L_143_)	
		
	local L_146_ = Instance.new("Part", L_66_)
	game.Debris:AddItem(L_146_, 10)
	L_146_.Shape = Enum.PartType.Ball
	L_146_.Size = Vector3.new(1, 1, 12)
	L_146_.Name = "Bullet"
	L_146_.TopSurface = "Smooth"
	L_146_.BottomSurface = "Smooth"
	L_146_.BrickColor = BrickColor.new("Bright green")
	L_146_.Material = "Neon"
	L_146_.CanCollide = false
		--Bullet.CFrame = FirePart.CFrame + (Grip.CFrame.p - Grip.CFrame.p)
	L_146_.CFrame = L_145_
		
	local L_147_ = Instance.new("Sound")
	L_147_.SoundId = "rbxassetid://341519743"
	L_147_.Looped = true
	L_147_:Play()
	L_147_.Parent = L_146_
	L_147_.Volume = 0.4
	L_147_.MaxDistance = 30
		
	local L_148_ = Instance.new("SpecialMesh", L_146_)
	L_148_.MeshType = "Sphere"
	L_148_.Scale = Vector3.new(0.2, 0.2, 0.8)
	
	L_146_.Transparency = 1
	local L_149_ = L_146_:GetMass()
	local L_150_ = Instance.new('BodyForce', L_146_)
		
	L_150_.Force = L_21_.BulletPhysics
	L_146_.Velocity = L_143_ * L_21_.BulletSpeed
		
	local L_151_ = Instance.new('Attachment', L_146_)
	L_151_.Position = Vector3.new(0.1, 0, 0)
	local L_152_ = Instance.new('Attachment', L_146_)
	L_152_.Position = Vector3.new(-0.1, 0, 0)
			
	local L_153_ = TracerCalculation()
		
	if L_21_.TracerEnabled == true and L_153_ then
		local L_154_ = Instance.new('Trail', L_146_)
		L_154_.Attachment0 = L_151_
		L_154_.Attachment1 = L_152_
		L_154_.Transparency = NumberSequence.new(L_21_.TracerTransparency)
		L_154_.LightEmission = L_21_.TracerLightEmission
		L_154_.TextureLength = L_21_.TracerTextureLength
		L_154_.Lifetime = L_21_.TracerLifetime
		L_154_.FaceCamera = L_21_.TracerFaceCamera
		L_154_.Color = ColorSequence.new(L_21_.TracerColor.Color)
	end
		
	if L_1_:FindFirstChild('Shell') then	
		CreateShell()	
	end	
		
	delay(0.2, function()
		L_146_.Transparency = 0
	end)
	
	return L_146_
end

function CheckForHumanoid(L_155_arg1)
	local L_156_
	local L_157_
	if (L_155_arg1.Parent:FindFirstChild("Humanoid") or L_155_arg1.Parent.Parent:FindFirstChild("Humanoid")) then
		L_156_ = true
		if L_155_arg1.Parent:FindFirstChild('Humanoid') then
			L_157_ = L_155_arg1.Parent.Humanoid
		elseif L_155_arg1.Parent.Parent:FindFirstChild('Humanoid') then
			L_157_ = L_155_arg1.Parent.Parent.Humanoid
		end
	else
		L_156_ = false
	end	
	return L_156_, L_157_
end

function CastRay(L_158_arg1)
	local L_159_, L_160_, L_161_
	local L_162_ = L_37_.Position;
	local L_163_ = L_158_arg1.Position;
	local L_164_ = 0
	while true do
		L_70_:wait()
		L_163_ = L_158_arg1.Position;
		L_164_ = L_164_ + (L_163_ - L_162_).magnitude
		L_159_, L_160_, L_161_ = workspace:FindPartOnRayWithIgnoreList(Ray.new(L_162_, (L_163_ - L_162_)), IgnoreList);
		local L_165_ = Vector3.new(0, 1, 0):Cross(L_161_)
		local L_166_ = math.asin(L_165_.magnitude) -- division by 1 is redundant
		if L_164_ > 10000 then
			break
		end
		if L_159_ and (L_159_ and L_159_.Transparency >= 1 or L_159_.CanCollide == false) then
			table.insert(IgnoreList, L_159_)
		end
	
		if L_159_ then
			L_165_ = Vector3.new(0, 1, 0):Cross(L_161_)
			L_166_ = math.asin(L_165_.magnitude) -- division by 1 is redundant
		
			local L_167_ = CheckForHumanoid(L_159_)
			if L_167_ == false then
				L_158_arg1:Destroy()
				L_77_:FireServer(L_160_, L_165_, L_166_, L_161_, "Part")
			elseif L_167_ == true then
				L_158_arg1:Destroy()
				L_77_:FireServer(L_160_, L_165_, L_166_, L_161_, "Human")
			end
		end
	
		if L_159_ and (L_159_.Parent:FindFirstChild("Humanoid") or L_159_.Parent.Parent:FindFirstChild("Humanoid")) then
			local L_168_, L_169_ = CheckForHumanoid(L_159_)
			if L_168_ then
				if L_21_.AntiTK then
					if game.Players:FindFirstChild(L_169_.Parent.Name) and game.Players:FindFirstChild(L_169_.Parent.Name).TeamColor ~= L_2_.TeamColor then
						if L_159_.Name == 'Head' then
							L_74_:FireServer(L_169_, L_21_.HeadDamage)
						elseif L_159_.Name ~= 'Head' and not (L_159_.Parent:IsA('Accessory') or L_159_.Parent:IsA('Hat')) then
							L_74_:FireServer(L_169_, L_21_.Damage)
						elseif (L_159_.Parent:IsA('Accessory') or L_159_.Parent:IsA('Hat')) then
							L_74_:FireServer(L_169_, L_21_.HeadDamage)
						end
					end
				else
					if L_159_.Name == 'Head' then
						L_74_:FireServer(L_169_, L_21_.HeadDamage)
					elseif L_159_.Name ~= 'Head' and not (L_159_.Parent:IsA('Accessory') or L_159_.Parent:IsA('Hat')) then
						L_74_:FireServer(L_169_, L_21_.Damage)
					elseif (L_159_.Parent:IsA('Accessory') or L_159_.Parent:IsA('Hat')) then
						L_74_:FireServer(L_169_, L_21_.HeadDamage)
					end
				end	
			end
		end
	
		if L_159_ and L_159_.Parent:FindFirstChild("Humanoid") then
			local L_170_
			if L_159_ and L_159_.Parent:FindFirstChild("Humanoid") or L_159_.Parent.Parent:FindFirstChild("Humanoid") then
				if L_159_.Parent:IsA("Accessory") then		
					L_170_ = L_159_.Parent.Parent.Humanoid
				elseif not L_159_.Parent:IsA("Accessory") then
					L_170_ = L_159_.Parent.Humanoid
				end
				L_75_:FireServer(L_170_)
			end
			return L_159_, L_160_;
		end
		L_162_ = L_163_;
	end
end

function fireSemi()
	if L_14_ then
		L_46_ = false
		Recoiling = true
		Shooting = true
		L_73_:FireServer()
		L_67_ = CreateBullet(0)
		L_68_ = L_68_ - 1
		RecoilFront = true
		local L_171_, L_172_ = spawn(function()
			CastRay(L_67_)
		end)
						
		for L_174_forvar1, L_175_forvar2 in pairs(L_37_:GetChildren()) do
			if L_175_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_175_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_176_forvar1, L_177_forvar2 in pairs(L_37_:GetChildren()) do
				if L_177_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_177_forvar2.Enabled = false
				end
			end
		end)
		
		if L_21_.CanBolt == true then
			BoltingBackAnim()
			delay(L_21_.Firerate / 2, function()
				if L_21_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_21_.CanSlideLock == true and L_68_ > 0 then
					BoltingBackAnim()
				end
			end)
		end
		
		delay(L_21_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)		
		
		wait(L_21_.Firerate)
		
		local L_173_ = JamCalculation()
		if L_173_ then
			L_46_ = false
		else
			L_46_ = true
		end
		Shooting = false
	end
end

function fireShot()
	if L_14_ then
		L_46_ = false
		Recoiling = true
		Shooting = true
		RecoilFront = true
		L_73_:FireServer()
		for L_179_forvar1 = 1, L_21_.ShotNum do
			L_67_ = CreateBullet(2)
			local L_180_, L_181_ = spawn(function()
				CastRay(L_67_)
			end)
		end
						
		for L_182_forvar1, L_183_forvar2 in pairs(L_37_:GetChildren()) do
			if L_183_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_183_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_184_forvar1, L_185_forvar2 in pairs(L_37_:GetChildren()) do
				if L_185_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_185_forvar2.Enabled = false
				end
			end
		end)
		
		if L_21_.CanBolt == true then
			BoltingBackAnim()
			delay(L_21_.Firerate / 2, function()
				if L_21_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_21_.CanSlideLock == true and L_68_ > 0 then
					BoltingBackAnim()
				end
			end)
		end
		
		delay(L_21_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		L_68_ = L_68_ - 1
		wait(L_21_.Firerate)
		
		local L_178_ = JamCalculation()
		if L_178_ then
			L_46_ = false
		else
			L_46_ = true
		end
		
		Shooting = false
	end
end

function fireBoltAction()
	if L_14_ then
		L_46_ = false
		Recoiling = true
		Shooting = true
		L_73_:FireServer()
		L_67_ = CreateBullet(0)
		L_68_ = L_68_ - 1
		RecoilFront = true
		local L_186_, L_187_ = spawn(function()
			CastRay(L_67_)
		end)
						
		for L_189_forvar1, L_190_forvar2 in pairs(L_37_:GetChildren()) do
			if L_190_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_190_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_191_forvar1, L_192_forvar2 in pairs(L_37_:GetChildren()) do
				if L_192_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_192_forvar2.Enabled = false
				end
			end
		end)
		
		if L_21_.CanBolt == true then
			BoltingBackAnim()
			delay(L_21_.Firerate / 2, function()
				if L_21_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_21_.CanSlideLock == true and L_68_ > 0 then
					BoltingBackAnim()
				end
			end)
		end
		
		delay(L_21_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		wait(L_21_.Firerate)
		
		BoltBackAnim()
		BoltForwardAnim()
		IdleAnim()
		
		local L_188_ = JamCalculation()
		if L_188_ then
			L_46_ = false
		else
			L_46_ = true
		end		
		
		Shooting = false
	end
end

function fireAuto()
	while not Shooting and L_68_ > 0 and L_45_ and L_46_ and L_14_ do
		L_46_ = false
		Recoiling = true
		L_73_:FireServer()
		L_68_ = L_68_ - 1
		Shooting = true
		RecoilFront = true
		L_67_ = CreateBullet(0)
		local L_193_, L_194_ = spawn(function()
			CastRay(L_67_)
		end)
					
		for L_196_forvar1, L_197_forvar2 in pairs(L_37_:GetChildren()) do
			if L_197_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_197_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_198_forvar1, L_199_forvar2 in pairs(L_37_:GetChildren()) do
				if L_199_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_199_forvar2.Enabled = false
				end
			end
		end)
		
		if L_21_.CanBolt == true then
			BoltingBackAnim()
			delay(L_21_.Firerate / 2, function()
				if L_21_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_21_.CanSlideLock == true and L_68_ > 0 then
					BoltingForwardAnim()
				end
			end)
		end
		
		
		delay(L_21_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		wait(L_21_.Firerate)
		
		local L_195_ = JamCalculation()
		if L_195_ then
			L_46_ = false
		else
			L_46_ = true
		end
		
		Shooting = false
	end
end

function fireBurst()
	if not Shooting and L_68_ > 0 and L_45_ and L_14_ then
		for L_200_forvar1 = 1, L_21_.BurstNum do
			if L_68_ > 0 and L_45_ then
				L_46_ = false
				Recoiling = true
				L_73_:FireServer()
				L_67_ = CreateBullet(0)
				local L_201_, L_202_ = spawn(function()
					CastRay(L_67_)
				end)
					
				for L_204_forvar1, L_205_forvar2 in pairs(L_37_:GetChildren()) do
					if L_205_forvar2.Name:sub(1, 7) == "FlashFX" then
						L_205_forvar2.Enabled = true
					end
				end
		
				delay(1 / 30, function()
					for L_206_forvar1, L_207_forvar2 in pairs(L_37_:GetChildren()) do
						if L_207_forvar2.Name:sub(1, 7) == "FlashFX" then
							L_207_forvar2.Enabled = false
						end
					end
				end)
			
				if L_21_.CanBolt == true then
					BoltingBackAnim()
					delay(L_21_.Firerate / 2, function()
						if L_21_.CanSlideLock == false then
							BoltingForwardAnim()
						elseif L_21_.CanSlideLock == true and L_68_ > 0 then
							BoltingForwardAnim()
						end
					end)
				end
			
				L_68_ = L_68_ - 1
				RecoilFront = true
				delay(L_21_.Firerate / 2, function()
					Recoiling = false
					RecoilFront = false
				end)
				wait(L_21_.Firerate)
			
				local L_203_ = JamCalculation()
				if L_203_ then
					L_46_ = false
				else
					L_46_ = true
				end
		
			end
			Shooting = true
		end
		Shooting = false
	end
end

function Shoot()
	if L_14_ and L_46_ then
		if L_59_ == 1 then
			fireSemi()
		elseif L_59_ == 2 then
			fireAuto()
		elseif L_59_ == 3 then
			fireBurst()	
		elseif L_59_ == 4 then
			fireBoltAction()
		elseif L_59_ == 5 then
			fireShot()
		end
	end
end