local U="\066\117\108\108\101\116\067\097\115\101\115"local H,X=pcall(function()physicsService:CreateCollisionGroup(U)end)if H then print("\067\114\101\097\116\101\100 \110\101\119 \099\111\108\108\105\115\105\111\110 \103\114\111\117\112")else warn("\067\111\108\108\105\115\105\111\110 \103\114\111\117\112 \097\108\114\101\097\100\121 \101\120\105\115\116\115")end physicsService:CollisionGroupSetCollidable(U,U,false)local function r(U)if U:FindFirstChild("\072\097\116\065\116\116\097\099\104\109\101\110\116")or U:FindFirstChild("\072\097\105\114\065\116\116\097\099\104\109\101\110\116")or U:FindFirstChild("\078\101\099\107\065\116\116\097\099\104\109\101\110\116")or U:FindFirstChild("\070\097\099\101\070\114\111\110\116\065\116\116\097\099\104\109\101\110\116")then return true else return false end end local function m(U,H,X,r,m,i)if i then local U=i.Size.Z/2 local m=NewCFrame(0,0,-(r-U))i.CFrame=(CFLookAt(H,H+X)):ToWorldSpace(m)end end local function i(H,X,m,i)local D=coroutine.create(function()local H=X.Instance local m=random(MinimumDamage,MaximumDamage)if H.Parent:IsA("\077\111\100\101\108")and not core.isAlly(H.Parent)then if H.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")then local U=(H:FindFirstAncestorWhichIsA("\077\111\100\101\108")):FindFirstChild("\072\117\109\097\110\111\105\100")if H.Name=="\072\101\097\100"then U:TakeDamage(m*headshotmultiplier)else U:TakeDamage(m)end local r=NewInstance("\083\111\117\110\100",H)r.PlayOnRemove=true r.SoundId=HitFleshSound r:Destroy()impact.WorldPosition=X.Position impact.BloodCloud:Emit(30)impact.BloodParticles:Emit(30)else local r=combat.getBulletHole(H)r.CFrame=NewCFrame(r.Position,r.Position+X.Normal)r.Position=X.Position local m=r.DebrisAttachment m.TinyDustParticles:Emit(15)m.MainDustEffect:Emit(15)m.SmokeEffect:Emit(15)debrisService:AddItem(r,5)for H=1,random(2,3),1 do local r=NewInstance("\080\097\114\116")r.Color=X.Instance.Color r.Material=X.Instance.Material local m=random(5)/20 r.Size=NewVector(m,m,m)r.CFrame=NewCFrame(X.Position)r.Anchored=false r.Velocity=NewVector(random(-20,20),random(10,20),random(-20,20))r.Parent=workspace.IgnoreFolder r:SetNetworkOwner(nil)physicsService:SetPartCollisionGroup(r,U)debrisService:AddItem(r,1)end local i=r.ImpactSound i.SoundId=HitWallSounds[random(1,#HitWallSounds)]i.Volume=1 i:Play()end elseif H.Parent:IsA("\065\099\099\101\115\115\111\114\121")then local U=r(H)if H.Parent.Parent:IsA("\077\111\100\101\108")and not core.isAlly(H.Parent.Parent)then local r=H.Parent.Parent if r:FindFirstChild("\072\117\109\097\110\111\105\100")then if U then r.Humanoid:TakeDamage(m*headshotmultiplier)else r.Humanoid:TakeDamage(m)end local i=NewInstance("\083\111\117\110\100",H)i.PlayOnRemove=true i.SoundId=HitFleshSound i:Destroy()impact.WorldPosition=X.Position impact.BloodCloud:Emit(30)impact.BloodParticles:Emit(30)end end end end)coroutine.resume(D)end function combat.getBulletHole(U)local H=bulletHoleCopy:Clone()H.Parent=workspace.IgnoreFolder local X=H.DebrisAttachment local r=H.Decal r.Color3=U.Color X.TinyDustParticles.Color=NewColorSequence(U.Color)X.MainDustEffect.Color=NewColorSequence(U.Color)X.SmokeEffect.Color=NewColorSequence(U.Color)return H end function combat.destroyBulletRelatedCopies()bulletCopy:Destroy()bulletCaseCopy:Destroy()bulletHoleCopy:Destroy()end function combat.getBullet()local U=bulletCopy:Clone()U.Parent=workspace.IgnoreFolder return U end function combat.getCase()local H=bulletCaseCopy:Clone()H.Parent=workspace.IgnoreFolder physicsService:SetPartCollisionGroup(H,U)return H end function pushBullet(U)U.CFrame=barrel.WorldCFrame*Angles(0,-rad(90),0)runService.Heartbeat:Wait()local H=barrel.WorldPosition local X=(NewCFrame(H,(barrel.WorldCFrame*NewCFrame(0,0,-5)).Position)*Angles(rad(random(-spread,spread)),rad(random(-spread,spread)),rad(random(-spread,spread)))).LookVector local r=X*bulletspeed local D=FastCast.new()local Q=FastCast.newBehavior()Q.Acceleration=bulletacceleration Q.RaycastParams=Params Q.AutoIgnoreFolder=false Q.CosmeticBulletContainer=workspace.IgnoreFolder Q.MaxDistance=maxdistance D:Fire(H,X,r,Q)local f=0 D.LengthChanged:Connect(function(H,X,r,i,D,Q)m(H,X,r,i,D,Q)f+=i if U then local H=U.Size.Z/2 local m=NewCFrame(0,0,-(i-H))U.CFrame=(CFLookAt(X,X+r)):ToWorldSpace(m)*Angles(0,-rad(90),0)end if f>=maxdistance and U~=nil then U:Destroy()end end)D.RayHit:Connect(function(H,X,r,m)i(H,X,r,m)debrisService:AddItem(U,.2)U.Transparency=1 end)end local D=1 function combat.shoot(U)if status:get("\119\101\097\112\111\110\067\111\111\108")and not status:get("\114\101\108\111\097\100\105\110\103")then status:set("\119\101\097\112\111\110\067\111\111\108",false)local H if SemiAtLongRange then if core.checkDist(U,myRoot)>60 then H=1 else H=burstamount end else H=burstamount end if not fullauto then for H=1,H,1 do if myHuman.Health<=0 or U.Parent.Humanoid.Health<=0 then break end if not SemiAtLongRange then if core.checkDist(myRoot,U)<7 then break end end wait(firerate)status:set("\109\097\103",status:get("\109\097\103")-1)local X=coroutine.create(function()barrel.MuzzleFlashEffect:Emit(15)barrel.MuzzleFlashInnerEffect:Emit(15)barrel.SmokeEffect:Emit(3)barrel.SparkEffect:Emit(20)lightFlash.Enabled=true wait(.05)lightFlash.Enabled=false end)coroutine.resume(X)if shotgunpellets>1 then for U=1,shotgunpellets,1 do spawn(function()local U=combat.getBullet()pushBullet(U)end)end else local U=combat.getBullet()pushBullet(U)end local r=combat.getCase()r.CFrame=chamber.WorldCFrame r.Velocity=(r.CFrame.RightVector*-20)*NewVector(1,-3,1)r.RotVelocity=NewVector(random(-0.2,.2),random(-0.2,.2),random(-0.2,.2))r:SetNetworkOwner(nil)debrisService:AddItem(r,2.5)fireSound:Play()local m=m4.HingeAttach1.Position m4.HingeAttach1.Position=m-NewVector(0,0,.2);(tweenService:Create(m4.HingeAttach1,TweenInfo.new(.1),{Position=m})):Play()end else local H=RaycastParams.new()H.FilterType=Enum.RaycastFilterType.Blacklist H.FilterDescendantsInstances={marine}local X,r=pcall(function()for X=1,status:get("\109\097\103"),1 do if myHuman.Health<=0 or U.Parent.Humanoid.Health<=0 then break end if core.checkDist(myRoot,U)<7 then break end local r=false local m=workspace:Raycast(myHead.Position,(U.Parent.Head.Position-myHead.Position).Unit*detectionrange,H)pcall(function()if m.Instance and m.Instance:IsDescendantOf(U.Parent)then r=true end end)if not r then break end wait(firerate)status:set("\109\097\103",status:get("\109\097\103")-1)local i=coroutine.create(function()barrel.MuzzleFlashEffect:Emit(15)barrel.MuzzleFlashInnerEffect:Emit(15)barrel.SmokeEffect:Emit(3)barrel.SparkEffect:Emit(20)lightFlash.Enabled=true wait(.05)lightFlash.Enabled=false end)coroutine.resume(i)if shotgunpellets>1 then for U=1,shotgunpellets,1 do spawn(function()local U=combat.getBullet()pushBullet(U)end)end else local U=combat.getBullet()pushBullet(U)end local D=combat.getCase()D.CFrame=chamber.WorldCFrame D.Velocity=(D.CFrame.RightVector*-20)*NewVector(1,-3,1)D.RotVelocity=NewVector(random(-0.2,.2),random(-0.2,.2),random(-0.2,.2))D:SetNetworkOwner(nil)debrisService:AddItem(D,2.5)fireSound:Play()local Q=m4.HingeAttach1.Position m4.HingeAttach1.Position=Q-NewVector(0,0,.2);(tweenService:Create(m4.HingeAttach1,TweenInfo.new(.1),{Position=Q})):Play()end end)if not X then warn(r)end end if status:get("\109\097\103")<=0 then wait(delaybeforereloading)actions.reload()end wait(mySettings.M4.Delay.Value)status:set("\119\101\097\112\111\110\067\111\111\108",true)end end function combat.throwGrenade(U)if status:get("\119\101\097\112\111\110\067\111\111\108")and status:get("\103\114\101\110\097\100\101\067\111\111\108")then status:set("\119\101\097\112\111\110\067\111\111\108",false)status:set("\103\114\101\110\097\100\101\067\111\111\108",false)actions.yieldWeapons()local H=marine.Grenade:Clone()H.Boom.PlayOnRemove=true H.Parent=workspace H.CanCollide=true H.CFrame=(marine["\082\105\103\104\116 \065\114\109"].CFrame*NewCFrame(0,-1.3,0))*Angles(0,0,rad(90))H:SetNetworkOwner(nil)debrisService:AddItem(H,5)marine.Grenade.Transparency=1 local X=NewInstance("\087\101\108\100\067\111\110\115\116\114\097\105\110\116",H)X.Part0=marine["\082\105\103\104\116 \065\114\109"]X.Part1=H throwAnimation:Play()marine.Grenade.Pin:Play()myHuman.AutoRotate=false for H=1,4,1 do wait(.1)myRoot.CFrame=CFLookAt(NewVector(myRoot.Position.X,myRoot.Position.Y,myRoot.Position.Z),NewVector(U.Position.X,myRoot.Position.Y,U.Position.Z))end myHuman.AutoRotate=true if myHuman.Health<=0 then return end throwAnimation:Stop()X.Part1=nil local r=U.Position+U.Velocity troubleshoot.mark(r)local m=core.checkDist(myRoot,U)local i=CFLookAt(myRoot.Position,r)H.Velocity=(myRoot.CFrame.LookVector+NewVector(0,1,0))*NewVector(m,m*1.5,m)touched=H.Touched:Connect(function(U)if not U:IsDescendantOf(marine)then touched:Disconnect()H.HitWall:Play()wait(.5)local U=NewInstance("\069\120\112\108\111\115\105\111\110",workspace)U.Position=H.Position U.BlastRadius=16 U.BlastPressure=0 U.Hit:Connect(function(U,H)local X=U.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")if X then core.applyDamage(X,20-H)end end)H:Destroy()debrisService:AddItem(U,2)end end)local D=H.Attach0 local Q=H.Attach1 local f=NewInstance("\084\114\097\105\108",H)f.Attachment0=D f.Attachment1=Q f.Lifetime=.5 f.Color=NewColorSequence(Color3.fromRGB(150,150,150))f.WidthScale=NewNumberSequence(1,0)core.spawn(function()wait(1)status:set("\119\101\097\112\111\110\067\111\111\108",true)wait(5)status:set("\103\114\101\110\097\100\101\067\111\111\108",true)marine.Grenade.Transparency=0 end)end end local Q=marine.Knife function combat.stab()local U=false for H,X in pairs((status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")).Parent:GetChildren())do if X:IsA("\066\097\115\101\080\097\114\116")and core.checkDist(X,myRoot)<7 then U=true end end if U then myHuman:MoveTo((status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")).Position)Q.Stab:Play()Q.Attack:Play()Q.KnifeTrail.Enabled=true if random(2)==1 then stabAnimation:Play(.1,1,2)else stabPunchAnimation:Play()end local U=(status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")).Parent local H=U.Humanoid local X=nil if U:FindFirstChild("\084\111\114\115\111")then X=U.Torso elseif U:FindFirstChild("\085\112\112\101\114\084\111\114\115\111")then X=U.UpperTorso end core.applyDamage(H,random(MinimumDamage,MaximumDamage))if H.Health<=0 then targeting.findTarget()end if X then impact.WorldPosition=X.Position+NewVector(random(-0.5,.5),random(-0.5,.5),random(-0.5,.5))impact.BloodCloud:Emit(30)impact.BloodParticles:Emit(30)end wait(.5)Q.KnifeTrail.Enabled=false else wait(.2)end end function combat.checkCluster(U)for H,X in ipairs(status:get("\097\099\116\105\118\101\065\108\108\105\101\115"))do if core.checkDist(U,X)<30 then return false end end for H,X in ipairs(status:get("\112\111\116\101\110\116\105\097\108\084\097\114\103\101\116\115"))do if X~=U then if core.checkDist(U,X)<15 then return true end end end return false end return combat

local BulletCases = "BulletCases"

local Success,Error = pcall(function()
	physicsService:CreateCollisionGroup(BulletCases)
end)

if Success then
	print("Created new collision group")
else
	warn("Collision group already exists")
end

physicsService:CollisionGroupSetCollidable(BulletCases,BulletCases,false)

local function IsHeadAccessory(Handle)
	if Handle:FindFirstChild("HatAttachment") or Handle:FindFirstChild("HairAttachment") or Handle:FindFirstChild("NeckAttachment") or Handle:FindFirstChild("FaceFrontAttachment") then
		return true
	else
		return false
	end
end

local function OnLengthChanged(Cast, LastPoint, Direction, Length, Velocity, Bullet)
	if Bullet then
		local BulletLength = Bullet.Size.Z/2
		local Offset = NewCFrame(0,0,-(Length - BulletLength))
		Bullet.CFrame = CFLookAt(LastPoint, LastPoint + Direction):ToWorldSpace(Offset)
	end
end

local function OnHit(Cast, Result, Velocity, Bullet)
	local HitCoroutine = coroutine.create(function()
		local Hit = Result.Instance
		local Damage = random(MinimumDamage,MaximumDamage)

		if Hit.Parent:IsA("Model") and not core.isAlly(Hit.Parent) then
			if Hit.Parent:FindFirstChild("Humanoid") then
				local Humanoid = Hit:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Humanoid")

				if Hit.Name == "Head" then
					Humanoid:TakeDamage(Damage * headshotmultiplier)
				else
					Humanoid:TakeDamage(Damage)
				end

				local HitSound = NewInstance("Sound",Hit)
				HitSound.PlayOnRemove = true
				HitSound.SoundId = HitFleshSound
				HitSound:Destroy()
				
				impact.WorldPosition = Result.Position
				impact.BloodCloud:Emit(30)
				impact.BloodParticles:Emit(30)
			else
				local newBulletHole = combat.getBulletHole(Hit)
				newBulletHole.CFrame = NewCFrame(newBulletHole.Position, newBulletHole.Position + Result.Normal)
				newBulletHole.Position = Result.Position
				
				local debrisAttachment = newBulletHole.DebrisAttachment
				debrisAttachment.TinyDustParticles:Emit(15)
				debrisAttachment.MainDustEffect:Emit(15)
				debrisAttachment.SmokeEffect:Emit(15)
				
				debrisService:AddItem(newBulletHole,5)
				
				for i = 1, random(2,3) do
					local chunk = NewInstance("Part")
					chunk.Color = Result.Instance.Color
					chunk.Material = Result.Instance.Material
					local size = random(5)/20
					chunk.Size = NewVector(size,size,size)
					chunk.CFrame = NewCFrame(Result.Position)
					chunk.Anchored = false
					chunk.Velocity = NewVector(random(-20,20),random(10,20),random(-20,20))
					chunk.Parent = workspace.IgnoreFolder
					chunk:SetNetworkOwner(nil)
					
					physicsService:SetPartCollisionGroup(chunk,BulletCases)
					debrisService:AddItem(chunk,1)
				end
				
				local HitSound = newBulletHole.ImpactSound
				HitSound.SoundId = HitWallSounds[random(1,#HitWallSounds)]
				HitSound.Volume = 1
				HitSound:Play()
			end
		elseif Hit.Parent:IsA("Accessory") then
			local IsAHeadAccessory = IsHeadAccessory(Hit)
			if Hit.Parent.Parent:IsA("Model") and not core.isAlly(Hit.Parent.Parent) then
				local Model = Hit.Parent.Parent
				if Model:FindFirstChild("Humanoid") then
					if IsAHeadAccessory then
						Model.Humanoid:TakeDamage(Damage * headshotmultiplier)
					else
						Model.Humanoid:TakeDamage(Damage)
					end

					local HitSound = NewInstance("Sound",Hit)
					HitSound.PlayOnRemove = true
					HitSound.SoundId = HitFleshSound
					HitSound:Destroy()
					
					impact.WorldPosition = Result.Position
					impact.BloodCloud:Emit(30)
					impact.BloodParticles:Emit(30)
				end
			end
		end

	end)
	
	coroutine.resume(HitCoroutine)
end

function combat.getBulletHole(partHit)
	local bulletHole = bulletHoleCopy:Clone()
	bulletHole.Parent = workspace.IgnoreFolder
	
	local debrisAttachment = bulletHole.DebrisAttachment
	local decal = bulletHole.Decal
	
	decal.Color3 = partHit.Color
	debrisAttachment.TinyDustParticles.Color = NewColorSequence(partHit.Color)
	debrisAttachment.MainDustEffect.Color = NewColorSequence(partHit.Color)
	debrisAttachment.SmokeEffect.Color = NewColorSequence(partHit.Color)

	return bulletHole
end

function combat.destroyBulletRelatedCopies()
	bulletCopy:Destroy()
	bulletCaseCopy:Destroy()
	bulletHoleCopy:Destroy()
end

function combat.getBullet() -- only reason im not creating bullet here anymore is because too many attachments and trails and im lazy.
	local bullet = bulletCopy:Clone()
	bullet.Parent = workspace.IgnoreFolder

	return bullet
end

function combat.getCase() -- same thing as bullet
	local case = bulletCaseCopy:Clone()
	case.Parent = workspace.IgnoreFolder
	
	physicsService:SetPartCollisionGroup(case,BulletCases)
	
	return case
end

function pushBullet(bullet)
	-- replaced all the code in this function
	bullet.CFrame = barrel.WorldCFrame * Angles(0,-rad(90),0)
	
	runService.Heartbeat:Wait()
	
	local origin = barrel.WorldPosition
	local direction = (NewCFrame(origin,(barrel.WorldCFrame * NewCFrame(0,0,-5)).Position) * Angles(rad(random(-spread,spread)),rad(random(-spread,spread)),rad(random(-spread,spread)))).LookVector
	
	local NewVelocity = direction * bulletspeed
	
	local NewCaster = FastCast.new()
	local Behaviour = FastCast.newBehavior()

	Behaviour.Acceleration = bulletacceleration
	Behaviour.RaycastParams = Params
	Behaviour.AutoIgnoreFolder = false
	Behaviour.CosmeticBulletContainer = workspace.IgnoreFolder
	Behaviour.MaxDistance = maxdistance
	
	NewCaster:Fire(origin, direction, NewVelocity, Behaviour)

	local MaxLength = 0 -- value starts at zero and works its way up to the maximum distance as the bullet travels (used to detect how far the cosmetic bullet travels before being destroyed if it reaches max distance)

	NewCaster.LengthChanged:Connect(function(Cast,LastPoint,NewDirection,Length,NewVelocity,Bullet)
		OnLengthChanged(Cast, LastPoint, NewDirection, Length, NewVelocity, Bullet)
		MaxLength += Length
		
		if bullet then
			local BulletLength = bullet.Size.Z/2
			local Offset = NewCFrame(0,0,-(Length - BulletLength))
			bullet.CFrame = CFLookAt(LastPoint, LastPoint + NewDirection):ToWorldSpace(Offset) * Angles(0,-rad(90),0)
		end

		if MaxLength >= maxdistance and bullet ~= nil then
			bullet:Destroy()
		end
	end)

	NewCaster.RayHit:Connect(function(Cast, Result, Velocity, Bullet)
		OnHit(Cast, Result, Velocity, Bullet)
		
		debrisService:AddItem(bullet,0.2)
		bullet.Transparency = 1
	end)
end

local flashIndex = 1
function combat.shoot(target)
	if status:get("weaponCool") and not status:get("reloading") then
		status:set("weaponCool",false)
		
		local shot
		
		if SemiAtLongRange then
			if core.checkDist(target,myRoot) > 60 then
				shot = 1
			else
				shot = burstamount
			end
		else
			shot = burstamount
		end
		
		if not fullauto then
			for i = 1, shot do
				if myHuman.Health <= 0 or target.Parent.Humanoid.Health <= 0 then break end
				
				if not SemiAtLongRange then
					if core.checkDist(myRoot,target) < 7 then break end
				end
				
				wait(firerate)
				status:set("mag",status:get("mag")-1)
				
				--flash:Emit(1)
				local FlashCoroutine = coroutine.create(function()
					barrel.MuzzleFlashEffect:Emit(15)
					barrel.MuzzleFlashInnerEffect:Emit(15)
					barrel.SmokeEffect:Emit(3)
					barrel.SparkEffect:Emit(20)
					lightFlash.Enabled = true 
					wait(0.05)
					lightFlash.Enabled = false 
				end)

				coroutine.resume(FlashCoroutine)
				--bullet.CFrame = m4.CFrame * NewCFrame(0,0.2,-2.5) --z: 0.5
				
				if shotgunpellets > 1 then
					for i = 1,shotgunpellets,1 do
						spawn(function()
							local bullet = combat.getBullet()
							pushBullet(bullet)
						end)
					end
				else
					local bullet = combat.getBullet()
					pushBullet(bullet)
				end
				
				local case = combat.getCase()
				case.CFrame = chamber.WorldCFrame
				case.Velocity = case.CFrame.RightVector * -20 * NewVector(1,-3,1)
				case.RotVelocity = NewVector(random(-0.2,0.2),random(-0.2,0.2),random(-0.2,0.2))
				case:SetNetworkOwner(nil)
				debrisService:AddItem(case,2.5)

				fireSound:Play()

				--Kick
				local original = m4.HingeAttach1.Position
				m4.HingeAttach1.Position = original - NewVector(0,0,0.2)
				tweenService:Create(m4.HingeAttach1, TweenInfo.new(0.1),{Position = original}):Play()
				
			end
		else
			local Params = RaycastParams.new()
			Params.FilterType = Enum.RaycastFilterType.Blacklist
			Params.FilterDescendantsInstances = {marine}
			
			local Success,Error = pcall(function() -- gonna make sure if something strange happens the whole script wont freeze
				for i = 1, status:get("mag") do
					if myHuman.Health <= 0 or target.Parent.Humanoid.Health <= 0 then break end
					
					if core.checkDist(myRoot,target) < 7 then break end
					
					local cansee = false
					local eyesight = workspace:Raycast(myHead.Position,(target.Parent.Head.Position - myHead.Position).Unit * detectionrange,Params)
					pcall(function()
						if eyesight.Instance and eyesight.Instance:IsDescendantOf(target.Parent) then
							cansee = true
						end
					end)
					
					if not cansee then break end
					
					wait(firerate)
					status:set("mag",status:get("mag")-1)

					--flash:Emit(1)
					local FlashCoroutine = coroutine.create(function()
						barrel.MuzzleFlashEffect:Emit(15)
						barrel.MuzzleFlashInnerEffect:Emit(15)
						barrel.SmokeEffect:Emit(3)
						barrel.SparkEffect:Emit(20)
						lightFlash.Enabled = true 
						wait(0.05)
						lightFlash.Enabled = false 
					end)

					coroutine.resume(FlashCoroutine)

					if shotgunpellets > 1 then
						for i = 1,shotgunpellets,1 do
							spawn(function()
								local bullet = combat.getBullet()
								pushBullet(bullet)
							end)
						end
					else
						local bullet = combat.getBullet()
						pushBullet(bullet)
					end

					local case = combat.getCase()
					case.CFrame = chamber.WorldCFrame
					case.Velocity = case.CFrame.RightVector * -20 * NewVector(1,-3,1)
					case.RotVelocity = NewVector(random(-0.2,0.2),random(-0.2,0.2),random(-0.2,0.2))
					case:SetNetworkOwner(nil)
					debrisService:AddItem(case,2.5)

					fireSound:Play()

					--Kick
					local original = m4.HingeAttach1.Position
					m4.HingeAttach1.Position = original - NewVector(0,0,0.2)
					tweenService:Create(m4.HingeAttach1, TweenInfo.new(0.1),{Position = original}):Play()

				end
			end)
			
			if not Success then
				warn(Error)
			end
		end
		if status:get("mag") <= 0 then
			wait(delaybeforereloading)
			actions.reload()
		end

		--New thread here before
		wait(mySettings.M4.Delay.Value)
		status:set("weaponCool",true)
	end
end

function combat.throwGrenade(target)
	if status:get("weaponCool") and status:get("grenadeCool") then
		status:set("weaponCool",false)
		status:set("grenadeCool",false)
		actions.yieldWeapons()
		
		local g = marine.Grenade:Clone()
		g.Boom.PlayOnRemove = true
		g.Parent = workspace
		g.CanCollide = true
		g.CFrame = marine["Right Arm"].CFrame * NewCFrame(0,-1.3,0) * Angles(0,0,rad(90))
		g:SetNetworkOwner(nil)
		debrisService:AddItem(g,5)
		
		marine.Grenade.Transparency = 1
		
		local w = NewInstance("WeldConstraint",g)
		w.Part0 = marine["Right Arm"]
		w.Part1 = g
		
		throwAnimation:Play()
		marine.Grenade.Pin:Play()
		
		--Rotate and throw
		myHuman.AutoRotate = false
		for i=1,4 do
			wait(0.1)
			myRoot.CFrame = CFLookAt(NewVector(myRoot.Position.X,myRoot.Position.Y,myRoot.Position.Z),NewVector(target.Position.X,myRoot.Position.Y,target.Position.Z))
		end
		myHuman.AutoRotate = true
		
		if myHuman.Health <= 0 then
			return
		end
		
		throwAnimation:Stop()
		
		w.Part1 = nil
		local targetPos = target.Position + (target.Velocity)
		troubleshoot.mark(targetPos)
		local dist = core.checkDist(myRoot,target)
		local aimCFrame = CFLookAt(myRoot.Position,targetPos)
		--g.Velocity = (aimCFrame.LookVector + NewVector(0,1.1,0)) * NewVector(dist,dist*1.5,dist)
		g.Velocity = (myRoot.CFrame.LookVector + NewVector(0,1,0)) * NewVector(dist,dist*1.5,dist)
		
		--Wait until grenade is thrown before it can be primed
		touched = g.Touched:Connect(function(obj)
			if not obj:IsDescendantOf(marine) then
				touched:Disconnect()
				g.HitWall:Play()
				wait(0.5)
				local x = NewInstance("Explosion",workspace)
				x.Position = g.Position
				x.BlastRadius = 16
				x.BlastPressure = 0
				x.Hit:Connect(function(obj,dist)
					local human = obj.Parent:FindFirstChild("Humanoid")
					if human then
						core.applyDamage(human,20-dist)
					end
				end)
				g:Destroy()
				debrisService:AddItem(x,2)
			end
		end)
		
		local attach0 = g.Attach0
		local attach1 = g.Attach1
		local t = NewInstance("Trail",g)
		t.Attachment0 = attach0
		t.Attachment1 = attach1
		t.Lifetime = 0.5
		t.Color = NewColorSequence(Color3.fromRGB(150,150,150))
		t.WidthScale = NewNumberSequence(1,0)
		
		core.spawn(function()
			wait(1)
			status:set("weaponCool",true)
			wait(5)
			status:set("grenadeCool",true)
			marine.Grenade.Transparency = 0
		end)
	end
end

local knife = marine.Knife
function combat.stab()
	
	local canStab = false
	for i,v in pairs(status:get("currentTarget").Parent:GetChildren()) do
		if v:IsA("BasePart") and core.checkDist(v,myRoot) < 7 then
			canStab = true
		end
	end
	if canStab then
		myHuman:MoveTo(status:get("currentTarget").Position)
		
		knife.Stab:Play()
		knife.Attack:Play()
		knife.KnifeTrail.Enabled = true
		
		if random(2) == 1 then
			stabAnimation:Play(0.1,1,2)
		else
			stabPunchAnimation:Play()
		end
		
		local targetcharacter = status:get("currentTarget").Parent
		local human = targetcharacter.Humanoid
		local torso = nil
		
		if targetcharacter:FindFirstChild("Torso") then
			torso = targetcharacter.Torso
		elseif targetcharacter:FindFirstChild("UpperTorso") then
			torso = targetcharacter.UpperTorso
		end
		
		core.applyDamage(human,random(MinimumDamage,MaximumDamage))
		if human.Health <= 0 then
			targeting.findTarget()
		end
		
		if torso then
			impact.WorldPosition = torso.Position + NewVector(random(-0.5,0.5),random(-0.5,0.5),random(-0.5,0.5))
			impact.BloodCloud:Emit(30)
			impact.BloodParticles:Emit(30)
		end
		
		--stabAnimation.Stopped:Wait()
		wait(0.5)
		knife.KnifeTrail.Enabled = false
	else
		wait(0.2)
	end
end

function combat.checkCluster(target)
	--Check for nearby allies
	for i,v in ipairs(status:get("activeAllies")) do
		if core.checkDist(target,v) < 30 then
			return false
		end
	end
	--Check if enemies are paired close together
	for i,v in ipairs(status:get("potentialTargets")) do
		if v ~= target then
			if core.checkDist(target,v) < 15 then
				return true
			end
		end
	end
	return false
end

return combat
