Run.RenderStepped:Connect(function(f)HeadMovement()renderGunRecoil()renderCam()if ViewModel and(LArm and(RArm and WeaponInHand))then local f=User:GetMouseDelta()SwaySpring:accelerate(Vector3.new(f.x/60,f.y/60,0))local I=SwaySpring.p local Y=I.z local Z=I.X local y=I.Y local V=CFrame.Angles(y,Z,Z)if BipodAtt then local f=Ray.new(UnderBarrelAtt.Main.Position,Vector3.new(0,-1.75,0))local I,Y,Z=workspace:FindPartOnRayWithIgnoreList(f,Ignore_Model,false,true)if I then CanBipod=true if CanBipod and(BipodActive and(not runKeyDown and(GunStance==0 or GunStance==2)))then(TS:Create(SE_GUI.GunHUD.Att.Bipod,TweenInfo.new(.1,Enum.EasingStyle.Linear),{ImageColor3=Color3.fromRGB(255,255,255);ImageTransparency=.123})):Play()if not aimming then BipodCF=BipodCF:Lerp(CFrame.new(0,((UnderBarrelAtt.Main.Position-Y).magnitude-1)*-1.5,0),.2)else BipodCF=BipodCF:Lerp(CFrame.new(),.2)end else BipodActive=false BipodCF=BipodCF:Lerp(CFrame.new(),.2);(TS:Create(SE_GUI.GunHUD.Att.Bipod,TweenInfo.new(.1,Enum.EasingStyle.Linear),{ImageColor3=Color3.fromRGB(255,255,0),ImageTransparency=.5})):Play()end else BipodActive=false CanBipod=false BipodCF=BipodCF:Lerp(CFrame.new(),.2);(TS:Create(SE_GUI.GunHUD.Att.Bipod,TweenInfo.new(.1,Enum.EasingStyle.Linear),{ImageColor3=Color3.fromRGB(255,0,0);ImageTransparency=.5})):Play()end end AnimPart.CFrame=((((cam.CFrame*NearZ)*BipodCF)*maincf)*gunbobcf)*aimcf if not AnimData.GunModelFixed then WeaponInHand:SetPrimaryPartCFrame(ViewModel.PrimaryPart.CFrame*guncf)end if running then gunbobcf=gunbobcf:Lerp(CFrame.new((.025*(charspeed/10))*math.sin(tick()*8),(.025*(charspeed/10))*math.cos(tick()*16),0)*CFrame.Angles(math.rad((1*(charspeed/10))*math.sin(tick()*16)),math.rad((1*(charspeed/10))*math.cos(tick()*8)),math.rad(0)),.1)else gunbobcf=gunbobcf:Lerp(CFrame.new(.005*math.sin(tick()*1.5),.005*math.cos(tick()*2.5),0),.1)end if CurAimpart and(aimming and(AnimDebounce and not CheckingMag))then if not NVG or WeaponInHand.AimPart:FindFirstChild("\078\086\065\105\109")==nil then if AimPartMode==1 then(TS:Create(cam,AimTween,{FieldOfView=ModTable.ZoomValue})):Play()maincf=maincf:Lerp((((maincf*CFrame.new(0,0,-0.5))*recoilcf)*V:inverse())*CurAimpart.CFrame:toObjectSpace(cam.CFrame),.2)else(TS:Create(cam,AimTween,{FieldOfView=ModTable.Zoom2Value})):Play()maincf=maincf:Lerp((((maincf*CFrame.new(0,0,-0.5))*recoilcf)*V:inverse())*CurAimpart.CFrame:toObjectSpace(cam.CFrame),.2)end else(TS:Create(cam,AimTween,{FieldOfView=70})):Play()maincf=maincf:Lerp((((maincf*CFrame.new(0,0,-0.5))*recoilcf)*V:inverse())*(WeaponInHand.AimPart.CFrame*WeaponInHand.AimPart.NVAim.CFrame):toObjectSpace(cam.CFrame),.2)end else(TS:Create(cam,AimTween,{FieldOfView=70})):Play()maincf=maincf:Lerp((AnimData.MainCFrame*recoilcf)*V:inverse(),.2)end for f,I in pairs(WeaponInHand:GetDescendants())do if I:IsA("\066\097\115\101\080\097\114\116")and I.Name=="\083\105\103\104\116\077\097\114\107"then local f=I.CFrame:pointToObjectSpace(cam.CFrame.Position)/I.Size local Y=I.SurfaceGui.Border.Scope Y.Position=UDim2.new(.5+f.x,0,.5-f.y,0)end end recoilcf=recoilcf:Lerp(CFrame.new()*CFrame.Angles(math.rad(RecoilSpring.p.X),math.rad(RecoilSpring.p.Y),math.rad(RecoilSpring.p.z)),.2)if WeaponData.CrossHair then if aimming then CHup=CHup:Lerp(UDim2.new(.5,0,.5,0),.2)CHdown=CHdown:Lerp(UDim2.new(.5,0,.5,0),.2)CHleft=CHleft:Lerp(UDim2.new(.5,0,.5,0),.2)CHright=CHright:Lerp(UDim2.new(.5,0,.5,0),.2)else local f=(((WeaponData.CrosshairOffset+BSpread)+(charspeed*WeaponData.WalkMult)*ModTable.WalkMult)/50)/10 CHup=CHup:Lerp(UDim2.new(.5,0,.5-f,0),.5)CHdown=CHdown:Lerp(UDim2.new(.5,0,.5+f,0),.5)CHleft=CHleft:Lerp(UDim2.new(.5-f,0,.5,0),.5)CHright=CHright:Lerp(UDim2.new(.5+f,0,.5,0),.5)end Crosshair.Position=UDim2.new(0,mouse.X,0,mouse.Y)Crosshair.Up.Position=CHup Crosshair.Down.Position=CHdown Crosshair.Left.Position=CHleft Crosshair.Right.Position=CHright else CHup=CHup:Lerp(UDim2.new(.5,0,.5,0),.2)CHdown=CHdown:Lerp(UDim2.new(.5,0,.5,0),.2)CHleft=CHleft:Lerp(UDim2.new(.5,0,.5,0),.2)CHright=CHright:Lerp(UDim2.new(.5,0,.5,0),.2)Crosshair.Position=UDim2.new(0,mouse.X,0,mouse.Y)Crosshair.Up.Position=CHup Crosshair.Down.Position=CHdown Crosshair.Left.Position=CHleft Crosshair.Right.Position=CHright end if BSpread then local f=time()if f-LastSpreadUpdate>(60/WeaponData.ShootRate)*2 and(not shooting and BSpread>WeaponData.MinSpread*ModTable.MinSpread)then BSpread=math.max(WeaponData.MinSpread*ModTable.MinSpread,BSpread-WeaponData.AimInaccuracyDecrease*ModTable.AimInaccuracyDecrease)end if f-LastSpreadUpdate>(60/WeaponData.ShootRate)*1.5 and(not shooting and RecoilPower>WeaponData.MinRecoilPower*ModTable.MinRecoilPower)then RecoilPower=math.max(WeaponData.MinRecoilPower*ModTable.MinRecoilPower,RecoilPower-WeaponData.RecoilPowerStepAmount*ModTable.RecoilPowerStepAmount)end end if LaserActive and Pointer~=nil then if NVG then Pointer.Transparency=0 Pointer.Beam.Enabled=true else if not gameRules.RealisticLaser then Pointer.Beam.Enabled=true else Pointer.Beam.Enabled=false end if IRmode then Pointer.Transparency=1 else Pointer.Transparency=0 end end for f,I in pairs(WeaponInHand:GetDescendants())do if I:IsA("\066\097\115\101\080\097\114\116")and I.Name=="\076\097\115\101\114\080\111\105\110\116"then local f=Ray.new(I.CFrame.Position,I.CFrame.LookVector*1000)local Y,Z,y=workspace:FindPartOnRayWithIgnoreList(f,Ignore_Model,false,true)if Y then Pointer.CFrame=CFrame.new(Z,Z+y)else Pointer.CFrame=CFrame.new(cam.CFrame.Position+I.CFrame.LookVector*2000,I.CFrame.LookVector)end if HalfStep and gameRules.ReplicatedLaser then Evt.SVLaser:FireServer(Z,1,Pointer.Color,IRmode,WeaponTool)end break end end end end end)

Run.RenderStepped:Connect(function(step)
	HeadMovement()
	renderGunRecoil()
	renderCam()

	if ViewModel and LArm and RArm and WeaponInHand then --Check if the weapon and arms are loaded

		local mouseDelta = User:GetMouseDelta()
		SwaySpring:accelerate(Vector3.new(mouseDelta.x/60, mouseDelta.y/60, 0))

		local swayVec = SwaySpring.p
		local TSWAY = swayVec.z
		local XSSWY = swayVec.X
		local YSSWY = swayVec.Y
		local Sway = CFrame.Angles(YSSWY,XSSWY,XSSWY)

		if BipodAtt then

			local BipodRay = Ray.new(UnderBarrelAtt.Main.Position, Vector3.new(0,-1.75,0))
			local BipodHit, BipodPos, BipodNorm = workspace:FindPartOnRayWithIgnoreList(BipodRay, Ignore_Model, false, true)

			if BipodHit then
				CanBipod = true
				if CanBipod and BipodActive and not runKeyDown and (GunStance == 0 or GunStance == 2) then
					TS:Create(SE_GUI.GunHUD.Att.Bipod, TweenInfo.new(.1,Enum.EasingStyle.Linear), {ImageColor3 = Color3.fromRGB(255,255,255), ImageTransparency = .123}):Play()
					if not aimming then
						BipodCF = BipodCF:Lerp(CFrame.new(0,(((UnderBarrelAtt.Main.Position - BipodPos).magnitude)-1) * (-1.5), 0),.2)
					else
						BipodCF = BipodCF:Lerp(CFrame.new(),.2)
					end				

				else
					BipodActive = false
					BipodCF = BipodCF:Lerp(CFrame.new(),.2)
					TS:Create(SE_GUI.GunHUD.Att.Bipod, TweenInfo.new(.1,Enum.EasingStyle.Linear), {ImageColor3 = Color3.fromRGB(255,255,0), ImageTransparency = .5}):Play()
				end
			else
				BipodActive = false
				CanBipod = false
				BipodCF = BipodCF:Lerp(CFrame.new(),.2)
				TS:Create(SE_GUI.GunHUD.Att.Bipod, TweenInfo.new(.1,Enum.EasingStyle.Linear), {ImageColor3 = Color3.fromRGB(255,0,0), ImageTransparency = .5}):Play()
			end

		end

		AnimPart.CFrame = cam.CFrame * NearZ * BipodCF * maincf * gunbobcf * aimcf

		if not AnimData.GunModelFixed then
			WeaponInHand:SetPrimaryPartCFrame(
				ViewModel.PrimaryPart.CFrame
					* guncf
			)
		end

		if running then
			gunbobcf = gunbobcf:Lerp(CFrame.new(
				0.025 * (charspeed/10) * math.sin(tick() * 8),
				0.025 * (charspeed/10) * math.cos(tick() * 16),
				0
				) * CFrame.Angles(
					math.rad( 1 * (charspeed/10) * math.sin(tick() * 16) ), 
					math.rad( 1 * (charspeed/10) * math.cos(tick() * 8) ), 
					math.rad(0)
				), 0.1)
		else
			gunbobcf = gunbobcf:Lerp(CFrame.new(
				0.005 * math.sin(tick() * 1.5),
				0.005 * math.cos(tick() * 2.5),
				0 
				), 0.1)
		end

		if CurAimpart and aimming and AnimDebounce and not CheckingMag then
			if not NVG or WeaponInHand.AimPart:FindFirstChild("NVAim") == nil then
				if AimPartMode == 1 then
					TS:Create(cam,AimTween,{FieldOfView = ModTable.ZoomValue}):Play()
					maincf = maincf:Lerp(maincf * CFrame.new(0,0,-.5) * recoilcf * Sway:inverse() * CurAimpart.CFrame:toObjectSpace(cam.CFrame), 0.2)
				else
					TS:Create(cam,AimTween,{FieldOfView = ModTable.Zoom2Value}):Play()
					maincf = maincf:Lerp(maincf * CFrame.new(0,0,-.5) * recoilcf * Sway:inverse() * CurAimpart.CFrame:toObjectSpace(cam.CFrame), 0.2)
				end
			else
				TS:Create(cam,AimTween,{FieldOfView = 70}):Play()
				maincf = maincf:Lerp(maincf * CFrame.new(0,0,-.5) * recoilcf * Sway:inverse() * (WeaponInHand.AimPart.CFrame * WeaponInHand.AimPart.NVAim.CFrame):toObjectSpace(cam.CFrame), 0.2)
			end

		else
			TS:Create(cam,AimTween,{FieldOfView = 70}):Play()
			maincf = maincf:Lerp(AnimData.MainCFrame * recoilcf * Sway:inverse(), 0.2)   
		end

		for index, Part in pairs(WeaponInHand:GetDescendants()) do
			if Part:IsA("BasePart") and Part.Name == "SightMark" then
				local dist_scale = Part.CFrame:pointToObjectSpace(cam.CFrame.Position)/Part.Size
				local reticle = Part.SurfaceGui.Border.Scope	
				reticle.Position=UDim2.new(.5+dist_scale.x,0,.5-dist_scale.y,0)	
			end
		end

		recoilcf = recoilcf:Lerp(CFrame.new() * CFrame.Angles( math.rad(RecoilSpring.p.X), math.rad(RecoilSpring.p.Y), math.rad(RecoilSpring.p.z)), 0.2)


		if WeaponData.CrossHair then
			if aimming then
				CHup = CHup:Lerp(UDim2.new(.5,0,.5,0),0.2)
				CHdown = CHdown:Lerp(UDim2.new(.5,0,.5,0),0.2)
				CHleft = CHleft:Lerp(UDim2.new(.5,0,.5,0),0.2)
				CHright = CHright:Lerp(UDim2.new(.5,0,.5,0),0.2)
			else
				local Normalized = ((WeaponData.CrosshairOffset + BSpread + (charspeed * WeaponData.WalkMult * ModTable.WalkMult) ) / 50)/10

				CHup = CHup:Lerp(UDim2.new(0.5, 0, 0.5 - Normalized,0),0.5)
				CHdown = CHdown:Lerp(UDim2.new(.5, 0, 0.5 + Normalized,0),0.5)
				CHleft = CHleft:Lerp(UDim2.new(.5 - Normalized, 0, 0.5, 0),0.5)
				CHright = CHright:Lerp(UDim2.new(.5 + Normalized, 0, 0.5, 0),0.5)
			end

			Crosshair.Position = UDim2.new(0,mouse.X,0,mouse.Y)

			Crosshair.Up.Position = CHup
			Crosshair.Down.Position = CHdown
			Crosshair.Left.Position = CHleft
			Crosshair.Right.Position = CHright

		else

			CHup = CHup:Lerp(UDim2.new(.5,0,.5,0),0.2)
			CHdown = CHdown:Lerp(UDim2.new(.5,0,.5,0),0.2)
			CHleft = CHleft:Lerp(UDim2.new(.5,0,.5,0),0.2)
			CHright = CHright:Lerp(UDim2.new(.5,0,.5,0),0.2)

			Crosshair.Position = UDim2.new(0,mouse.X,0,mouse.Y)

			Crosshair.Up.Position = CHup
			Crosshair.Down.Position = CHdown
			Crosshair.Left.Position = CHleft
			Crosshair.Right.Position = CHright

		end

		if BSpread then
			local currTime = time()
			if currTime - LastSpreadUpdate > (60/WeaponData.ShootRate) * 2 and not shooting and BSpread > WeaponData.MinSpread * ModTable.MinSpread then
				BSpread = math.max(WeaponData.MinSpread * ModTable.MinSpread, BSpread - WeaponData.AimInaccuracyDecrease * ModTable.AimInaccuracyDecrease)
			end
			if currTime - LastSpreadUpdate > (60/WeaponData.ShootRate) * 1.5 and not shooting and RecoilPower > WeaponData.MinRecoilPower * ModTable.MinRecoilPower then
				RecoilPower =  math.max(WeaponData.MinRecoilPower * ModTable.MinRecoilPower, RecoilPower - WeaponData.RecoilPowerStepAmount * ModTable.RecoilPowerStepAmount)
			end
		end

		if LaserActive and Pointer ~= nil then

			if NVG then
				Pointer.Transparency = 0
				Pointer.Beam.Enabled = true
			else
				if not gameRules.RealisticLaser then
					Pointer.Beam.Enabled = true
				else
					Pointer.Beam.Enabled = false
				end
				if IRmode then
					Pointer.Transparency = 1
				else
					Pointer.Transparency = 0
				end
			end
			
			for index, Key in pairs(WeaponInHand:GetDescendants()) do
				if Key:IsA("BasePart") and Key.Name == "LaserPoint" then
					local L_361_ = Ray.new(Key.CFrame.Position, Key.CFrame.LookVector * 1000)
					local Hit, Pos, Normal = workspace:FindPartOnRayWithIgnoreList(L_361_, Ignore_Model, false, true)

					if Hit then
						Pointer.CFrame =  CFrame.new(Pos, Pos + Normal)
					else
						Pointer.CFrame =  CFrame.new(cam.CFrame.Position + Key.CFrame.LookVector * 2000, Key.CFrame.LookVector)
					end

					if HalfStep and gameRules.ReplicatedLaser then
						Evt.SVLaser:FireServer(Pos,1,Pointer.Color,IRmode,WeaponTool)
					end
					break
				end
			end
		end
	end
end)