function Fire_Gun()local V=Handle:FindFirstChild("\070\105\114\101\083\111\117\110\100")local n=Main:FindFirstChild("\070\108\097\115\104\071\117\105")local v=Main:FindFirstChild("\070\108\097\115\104\070\088")if V then V:Play()end local i=(not Aimed and(CurrentSpread<=S.Spread.Max and Idleing))and CurrentSpread*S.Spread.Multiplier or CurrentSpread CurrentSpread=i>=S.Spread.Max and S.Spread.Max or i for V=1,S.GunType.Shot and S.ShotAmount or 1,1 do local n=CFANG(RAD(RAND(-CurrentSpread,CurrentSpread)/20),RAD(RAND(-CurrentSpread,CurrentSpread)/20),RAD(RAND(-CurrentSpread,CurrentSpread)/20))local v=Aimed and(S.GuiScope and Head.CFrame or Handle.CFrame)or Head.CFrame local i=Main.CFrame.p local P=(CF(v.p,v.p+v.lookVector)*n).lookVector if S.InstantHit then local V,n=AdvRayCast(Main.CFrame.p,P,S.BulletRange)local v=nil if V then if S.GunType.Explosive then if S.ExplosionSound~=""then local V=Instance.new("\080\097\114\116")V.Transparency=1 V.Anchored=true V.CanCollide=false V.CFrame=CFrame.new(n)V.Parent=game.Workspace local v=Instance.new("\083\111\117\110\100")v.Pitch=S.ExplosionSoundPitch v.SoundId=S.ExplosionSound v.Volume=S.ExplosionSoundVolume v.Parent=V v:Play()delay(.05,function()V:Destroy()end)end CreateBulletHole(n,V)CreateShockwave(n,S.ExplosionRadius)local v=Instance.new("\069\120\112\108\111\115\105\111\110")v.BlastPressure=S.ExplosionPressure v.BlastRadius=S.ExplosionRadius v.DestroyJointRadiusPercent=S.RangeBasedDamage and 0 or 1 v.ExplosionType=S.ExplosionType v.Position=n v.Hit:connect(function(V,v)if V.Name=="\084\111\114\115\111"and not V:IsDescendantOf(Character)then if S.RangeBasedDamage then local i=(V.Position-n).unit local P,C=AdvRayCast(n-i,i,999)local K=P:IsDescendantOf(V.Parent)if S.RayCastExplosions and K or not S.RayCastExplosions then local n=FindFirstClass(V.Parent,"\072\117\109\097\110\111\105\100")if n and(n.Health>0 and IsEnemy(n))then local V=v/S.ExplosionRadius local i=math.max(1-V,0)local P=i*S.Damage local C=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")C.Value=Player C.Name="\099\114\101\097\116\111\114"C.Parent=n n:TakeDamage(P)MarkHit()end end else local n=FindFirstClass(V.Parent,"\072\117\109\097\110\111\105\100")if n and(n.Health>0 and IsEnemy(n))then local V=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")V.Value=Player V.Name="\099\114\101\097\116\111\114"V.Parent=n MarkHit()end end end end)v.Parent=game.Workspace else v=Damage(V,n)end end local C=n if S.Penetration>0 and not S.GunType.Explosive then C=PenetrateWall(n,P,v,i)end if S.BulletTrail and S.TrailTransparency~=1 then local V=Instance.new("\080\097\114\116")V.BrickColor=S.TrailColor V.Transparency=S.TrailTransparency V.Anchored=true V.CanCollide=false V.Size=VEC3(1,1,1)local n=Instance.new("\066\108\111\099\107\077\101\115\104")n.Offset=VEC3(0,0,-(C-i).magnitude/2)n.Scale=VEC3(S.TrailThickness,S.TrailThickness,(C-i).magnitude)n.Parent=V V.Parent=Gun_Ignore V.CFrame=CF(i,C)delay(S.TrailVisibleTime,function()if S.TrailDisappearTime>0 then local n=0 while true do if n==90 then break end if not Selected then break end local v=n+1.5/S.TrailDisappearTime n=v>90 and 90 or v local i=n/90 V.Transparency=NumLerp(S.TrailTransparency,1,i)RS:wait()end V:Destroy()else V:Destroy()end end)end else local V=CreateBullet(P)local n=Main.CFrame.p local v=0 local C=nil spawn(function()while true do RS:wait()if v>=S.BulletRange then V:Destroy()break end local P=(V.Position-n).magnitude local K,e=AdvRayCast(n,(V.Position-n).unit,P)if K then if S.GunType.Explosive then if S.ExplosionSound~=""then local n=Instance.new("\083\111\117\110\100")n.Pitch=S.ExplosionSoundPitch n.SoundId=S.ExplosionSound n.Volume=S.ExplosionSoundVolume n.Parent=V n:Play()end CreateBulletHole(e,K)CreateShockwave(e,S.ExplosionRadius)local n=Instance.new("\069\120\112\108\111\115\105\111\110")n.BlastPressure=S.ExplosionPressure n.BlastRadius=S.ExplosionRadius n.DestroyJointRadiusPercent=S.RangeBasedDamage and 0 or 1 n.ExplosionType=S.ExplosionType n.Position=e n.Hit:connect(function(V,n)if V.Name=="\084\111\114\115\111"and not V:IsDescendantOf(Character)then if S.RangeBasedDamage then local v=(V.Position-e).unit local i,P=AdvRayCast(e-v,v,999)local C=i:IsDescendantOf(V.Parent)if S.RayCastExplosions and C or not S.RayCastExplosions then local v=FindFirstClass(V.Parent,"\072\117\109\097\110\111\105\100")if v and(v.Health>0 and IsEnemy(v))then local V=n/S.ExplosionRadius local i=math.max(1-V,0)local P=i*S.Damage local C=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")C.Value=Player C.Name="\099\114\101\097\116\111\114"C.Parent=v v:TakeDamage(P)MarkHit()end end else local n=FindFirstClass(V.Parent,"\072\117\109\097\110\111\105\100")if n and(n.Health>0 and IsEnemy(n))then local V=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")V.Value=Player V.Name="\099\114\101\097\116\111\114"V.Parent=n MarkHit()end end end end)n.Parent=game.Workspace else C=Damage(K,e)end if S.Penetration>0 and not S.GunType.Explosive then PenetrateWall(e,(V.Position-n).unit,C,i,V)else V:Destroy()end break else n=V.Position v=v+P end end end)if S.BulletTrail and S.TrailTransparency~=1 then spawn(function()local n=nil while true do if n then if not V:IsDescendantOf(game)then break end V.CFrame=CFrame.new(V.CFrame.p,V.CFrame.p+V.Velocity)local v=Instance.new("\080\097\114\116")v.BrickColor=S.TrailColor v.Transparency=S.TrailTransparency v.Anchored=true v.CanCollide=false v.Size=VEC3(1,1,1)local i=Instance.new("\066\108\111\099\107\077\101\115\104")i.Offset=VEC3(0,0,-(V.Position-n).magnitude/2)i.Scale=VEC3(S.TrailThickness,S.TrailThickness,(V.Position-n).magnitude)i.Parent=v v.Parent=Gun_Ignore v.CFrame=CF(n,V.Position)delay(S.TrailVisibleTime,function()if S.TrailDisappearTime>0 then local V=0 while true do if V==90 then break end if not Selected then break end local n=V+1.5/S.TrailDisappearTime V=n>90 and 90 or n local i=V/90 v.Transparency=NumLerp(S.TrailTransparency,1,i)RS:wait()end v:Destroy()else v:Destroy()end end)n=V.Position else n=Main.CFrame.p end RS:wait()end end)end end end local P=RAD(CurrentRecoil*RAND(1,1.5,.1))*StanceSway local C=RAD(CurrentRecoil*RAND(-2,2,.1))*StanceSway RotCamera(P,C,true,.06)delay(.05,function()RotCamera(-P/5,-C/5,true,.1)end)if Idleing and(not Walking and not Aimed)then local V=(CurrentSpread/S.Spread.Max)*50 Gui_Clone.CrossHair.Box:TweenSizeAndPosition(UDim2.new(0,70+2*V,0,70+2*V),UDim2.new(0,-35-V,0,-35-V),"\079\117\116","\076\105\110\101\097\114",.1,true)end local K=({CurrentRecoil*(RAND(1,5,1)/150),CurrentRecoil*(RAND(1,5,1)/-150)})[math.random(1,2)]*StanceSway local e=(CurrentRecoil*StanceSway)*.3 local b=RAD(90+(CurrentRecoil*RAND(1.3,1.4,.01))*StanceSway)TweenJoint(AnimWeld,CF(K,1,-e),CFANG(b-RAD(90),0,0),Linear,.083333333333333)if v then v.Enabled=true end if n then n.Enabled=true n.Label.Rotation=RAND(0,360)end delay(.033333333333333,function()if Idleing and(not Walking and not Aimed)then Gui_Clone.CrossHair.Box:TweenSizeAndPosition(UDim2.new(0,70,0,70),UDim2.new(0,-35,0,-35),"\079\117\116","\076\105\110\101\097\114",S.AimSpeed,not Aimed)end if not Aiming and not RunTween then TweenJoint(AnimWeld,CF(0,1,0),CF(),Linear,.15)end if v then v.Enabled=false end if n then n.Enabled=false end end)end function MarkHit()spawn(function()if Gui_Clone:IsDescendantOf(game)then Gui_Clone.HitMarker.Visible=true local V=tick()LastMark=V wait(.5)if LastMark<=V then Gui_Clone.HitMarker.Visible=false end end end)end


function Fire_Gun()
	local FireSound = Handle:FindFirstChild("FireSound")
	local FlashGui = Main:FindFirstChild("FlashGui")
	local FlashFX = Main:FindFirstChild("FlashFX")
				
	if FireSound then FireSound:Play() end
	
	local MockSpread = (
		((not Aimed) and CurrentSpread <= S.Spread.Max and Idleing)
		and CurrentSpread * S.Spread.Multiplier or CurrentSpread
	)
	CurrentSpread = (MockSpread >= S.Spread.Max and S.Spread.Max or MockSpread)
	
	----------------------------------------------------------------------------------
	for _ = 1, (S.GunType.Shot and S.ShotAmount or 1) do
		local BSpread = CFANG(
			RAD(RAND(-CurrentSpread, CurrentSpread) / 20),
			RAD(RAND(-CurrentSpread, CurrentSpread) / 20),
			RAD(RAND(-CurrentSpread, CurrentSpread) / 20)
		)
		local OriginCF = (Aimed and (S.GuiScope and Head.CFrame or Handle.CFrame) or Head.CFrame)
		local OriginPos = Main.CFrame.p
		local Direction = (CF(OriginCF.p, OriginCF.p + OriginCF.lookVector) * BSpread).lookVector
		
		if S.InstantHit then
			local HitObj, HitPos = AdvRayCast(Main.CFrame.p, Direction, S.BulletRange)
			local HitHumanoid = nil
			if HitObj then
				if S.GunType.Explosive then
					if S.ExplosionSound ~= "" then
						local SoundPart = Instance.new("Part")
						SoundPart.Transparency = 1
						SoundPart.Anchored = true
						SoundPart.CanCollide = false
						SoundPart.CFrame = CFrame.new(HitPos)
						SoundPart.Parent = game.Workspace
						
						local Sound = Instance.new("Sound")
						Sound.Pitch = S.ExplosionSoundPitch
						Sound.SoundId = S.ExplosionSound
						Sound.Volume = S.ExplosionSoundVolume
						Sound.Parent = SoundPart
						Sound:Play()
						
						delay(1 / 20, function()
							SoundPart:Destroy()
						end)
					end
					CreateBulletHole(HitPos, HitObj)
					CreateShockwave(HitPos, S.ExplosionRadius)
					local E = Instance.new("Explosion")
					E.BlastPressure = S.ExplosionPressure
					E.BlastRadius = S.ExplosionRadius
					E.DestroyJointRadiusPercent = (S.RangeBasedDamage and 0 or 1)
					E.ExplosionType = S.ExplosionType
					E.Position = HitPos
					E.Hit:connect(function(HObj, HDist)
						if HObj.Name == "Torso" and (not HObj:IsDescendantOf(Character)) then
							if S.RangeBasedDamage then
								local Dir = (HObj.Position - HitPos).unit
								local H, P = AdvRayCast(HitPos - Dir, Dir, 999)
								local RayHitHuman = H:IsDescendantOf(HObj.Parent)
								if (S.RayCastExplosions and RayHitHuman) or (not S.RayCastExplosions) then
									local HitHumanoid = FindFirstClass(HObj.Parent, "Humanoid")
									if HitHumanoid and HitHumanoid.Health > 0 and IsEnemy(HitHumanoid) then
										local DistFactor = HDist / S.ExplosionRadius
										local DistInvert = math.max(1 - DistFactor,0)
										local NewDamage = DistInvert * S.Damage
										
										local CreatorTag = Instance.new("ObjectValue")
										CreatorTag.Value = Player
										CreatorTag.Name = "creator"
										CreatorTag.Parent = HitHumanoid
										HitHumanoid:TakeDamage(NewDamage)
										MarkHit()
									end
								end
							else
								local HitHumanoid = FindFirstClass(HObj.Parent, "Humanoid")
								if HitHumanoid and HitHumanoid.Health > 0 and IsEnemy(HitHumanoid) then
									local CreatorTag = Instance.new("ObjectValue")
									CreatorTag.Value = Player
									CreatorTag.Name = "creator"
									CreatorTag.Parent = HitHumanoid
									MarkHit()
								end
							end
						end
					end)
					E.Parent = game.Workspace
				else
					HitHumanoid = Damage(HitObj, HitPos)
				end
			end
			local FinalHitPos = HitPos
			if S.Penetration > 0 and (not S.GunType.Explosive) then
				FinalHitPos = PenetrateWall(HitPos, Direction, HitHumanoid, OriginPos)
			end
			if S.BulletTrail and S.TrailTransparency ~= 1 then
				local Trail = Instance.new("Part")
				Trail.BrickColor = S.TrailColor
				Trail.Transparency = S.TrailTransparency
				Trail.Anchored = true
				Trail.CanCollide = false
				Trail.Size = VEC3(1, 1, 1)
				local Mesh = Instance.new("BlockMesh")
				Mesh.Offset = VEC3(0, 0, -(FinalHitPos - OriginPos).magnitude / 2)
				Mesh.Scale = VEC3(S.TrailThickness, S.TrailThickness, (FinalHitPos - OriginPos).magnitude)
				Mesh.Parent = Trail
				Trail.Parent = Gun_Ignore
				Trail.CFrame = CF(OriginPos, FinalHitPos)
				delay(S.TrailVisibleTime, function()
					if S.TrailDisappearTime > 0 then
						local X = 0
						while true do
							if X == 90 then break end
							if (not Selected) then break end
							local NewX = X + (1.5 / S.TrailDisappearTime)
							X = (NewX > 90 and 90 or NewX)
							local Alpha = X / 90
							Trail.Transparency = NumLerp(S.TrailTransparency, 1, Alpha)
							RS:wait()
						end
						Trail:Destroy()
					else
						Trail:Destroy()
					end
				end)
			end
		else
			local Bullet = CreateBullet(Direction)
			local LastPos = Main.CFrame.p
			local TotalDistTraveled = 0
			local HitHumanoid = nil
			spawn(function()
				while true do
					RS:wait()
					if TotalDistTraveled >= S.BulletRange then
						Bullet:Destroy()
						break
					end
					local DistTraveled = (Bullet.Position - LastPos).magnitude
					local HitObj, HitPos = AdvRayCast(LastPos, (Bullet.Position - LastPos).unit, DistTraveled)
					if HitObj then
						if S.GunType.Explosive then
							if S.ExplosionSound ~= "" then
								local Sound = Instance.new("Sound")
								Sound.Pitch = S.ExplosionSoundPitch
								Sound.SoundId = S.ExplosionSound
								Sound.Volume = S.ExplosionSoundVolume
								Sound.Parent = Bullet
								Sound:Play()
							end
							CreateBulletHole(HitPos, HitObj)
							CreateShockwave(HitPos, S.ExplosionRadius)
							local E = Instance.new("Explosion")
							E.BlastPressure = S.ExplosionPressure
							E.BlastRadius = S.ExplosionRadius
							E.DestroyJointRadiusPercent = (S.RangeBasedDamage and 0 or 1)
							E.ExplosionType = S.ExplosionType
							E.Position = HitPos
							E.Hit:connect(function(HObj, HDist)
								if HObj.Name == "Torso" and (not HObj:IsDescendantOf(Character)) then
									if S.RangeBasedDamage then
										local Dir = (HObj.Position - HitPos).unit
										local H, P = AdvRayCast(HitPos - Dir, Dir, 999)
										local RayHitHuman = H:IsDescendantOf(HObj.Parent)
										if (S.RayCastExplosions and RayHitHuman) or (not S.RayCastExplosions) then
											local HitHumanoid = FindFirstClass(HObj.Parent, "Humanoid")
											if HitHumanoid and HitHumanoid.Health > 0 and IsEnemy(HitHumanoid) then
												local DistFactor = HDist / S.ExplosionRadius
												local DistInvert = math.max(1 - DistFactor,0)
												local NewDamage = DistInvert * S.Damage
												
												local CreatorTag = Instance.new("ObjectValue")
												CreatorTag.Value = Player
												CreatorTag.Name = "creator"
												CreatorTag.Parent = HitHumanoid
												HitHumanoid:TakeDamage(NewDamage)
												MarkHit()
											end
										end
									else
										local HitHumanoid = FindFirstClass(HObj.Parent, "Humanoid")
										if HitHumanoid and HitHumanoid.Health > 0 and IsEnemy(HitHumanoid) then
											local CreatorTag = Instance.new("ObjectValue")
											CreatorTag.Value = Player
											CreatorTag.Name = "creator"
											CreatorTag.Parent = HitHumanoid
											MarkHit()
										end
									end
								end
							end)
							E.Parent = game.Workspace
						else
							HitHumanoid = Damage(HitObj, HitPos)
						end
						if S.Penetration > 0 and (not S.GunType.Explosive) then
							PenetrateWall(HitPos, (Bullet.Position - LastPos).unit, HitHumanoid, OriginPos, Bullet)
						else
							Bullet:Destroy()
						end
						break
					else
						LastPos = Bullet.Position
						TotalDistTraveled = TotalDistTraveled + DistTraveled
					end
				end
			end)
			
			if S.BulletTrail and S.TrailTransparency ~= 1 then
				spawn(function()
					local LastPos2 = nil
					while true do
						if LastPos2 then
							if (not Bullet:IsDescendantOf(game)) then break end
							Bullet.CFrame = CFrame.new(Bullet.CFrame.p, Bullet.CFrame.p + Bullet.Velocity)
							local Trail = Instance.new("Part")
							Trail.BrickColor = S.TrailColor
							Trail.Transparency = S.TrailTransparency
							Trail.Anchored = true
							Trail.CanCollide = false
							Trail.Size = VEC3(1, 1, 1)
							local Mesh = Instance.new("BlockMesh")
							Mesh.Offset = VEC3(0, 0, -(Bullet.Position - LastPos2).magnitude / 2)
							Mesh.Scale = VEC3(S.TrailThickness, S.TrailThickness, (Bullet.Position - LastPos2).magnitude)
							Mesh.Parent = Trail
							Trail.Parent = Gun_Ignore
							Trail.CFrame = CF(LastPos2, Bullet.Position)
							delay(S.TrailVisibleTime, function()
								if S.TrailDisappearTime > 0 then
									local X = 0
									while true do
										if X == 90 then break end
										if (not Selected) then break end
										local NewX = X + (1.5 / S.TrailDisappearTime)
										X = (NewX > 90 and 90 or NewX)
										local Alpha = X / 90
										Trail.Transparency = NumLerp(S.TrailTransparency, 1, Alpha)
										RS:wait()
									end
									Trail:Destroy()
								else
									Trail:Destroy()
								end
							end)
							LastPos2 = Bullet.Position
						else
							LastPos2 = Main.CFrame.p
						end
						RS:wait()
					end
				end)
			end
		end
	end
	
	----------------------------------------------------------------------------------
	
	local RecoilX = RAD(CurrentRecoil * RAND(1, 1.5, 0.1)) * StanceSway
	local RecoilY = RAD(CurrentRecoil * RAND(-2, 2, 0.1)) * StanceSway
	RotCamera(RecoilX, RecoilY, true, 0.06)
	delay(0.05, function()
		RotCamera(-RecoilX / 5, -RecoilY / 5, true, 0.1)
	end)
	if Idleing and (not Walking) and (not Aimed) then
		local SpreadScale = (CurrentSpread / S.Spread.Max) * 50
		Gui_Clone.CrossHair.Box:TweenSizeAndPosition(
			UDim2.new(0, 70 + 2 * SpreadScale, 0, 70 + 2 * SpreadScale),
			UDim2.new(0, -35 - SpreadScale, 0, -35 - SpreadScale),
			"Out", "Linear", 0.1, true
		)
	end
	
	local KickSide = (
		(
			{
				CurrentRecoil * (RAND(1, 5, 1) / 150);
				CurrentRecoil * (RAND(1, 5, 1) / -150)
			}
		)[math.random(1, 2)]
	) * StanceSway
	local KickBack = CurrentRecoil * StanceSway * 0.3
	local KickUp = RAD(90 + (CurrentRecoil * RAND(1.3, 1.4, 0.01) * StanceSway))
	TweenJoint(AnimWeld, CF(KickSide, 1, -KickBack), CFANG(KickUp - RAD(90), 0, 0), Linear, 1 / 12)
	
	if FlashFX then FlashFX.Enabled = true end
	if FlashGui then
		FlashGui.Enabled = true
		FlashGui.Label.Rotation = RAND(0, 360)
	end
	
	delay(1 / 30, function()
		if Idleing and (not Walking) and (not Aimed) then
			Gui_Clone.CrossHair.Box:TweenSizeAndPosition(
				UDim2.new(0, 70, 0, 70),
				UDim2.new(0, -35, 0, -35),
				"Out", "Linear", S.AimSpeed, (not Aimed)
			)
		end
		if (not Aiming) and (not RunTween) then
			TweenJoint(AnimWeld, CF(0, 1, 0), CF(), Linear, 0.15)
		end
		if FlashFX then FlashFX.Enabled = false end
		if FlashGui then FlashGui.Enabled = false end
	end)
end

function MarkHit()
	spawn(function()
		if Gui_Clone:IsDescendantOf(game) then
			Gui_Clone.HitMarker.Visible = true
			local StartMark = tick()
			LastMark = StartMark
			wait(0.5)
			if LastMark <= StartMark then
				Gui_Clone.HitMarker.Visible = false
			end
		end
	end)
end
