stepped_con=(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:Connect(function()debug.profilebegin("\070\080\083")swaysize=script.WalkSwayMultiplier.Value checkfirstperson()if isfirstperson==true then local Z=0 local R=player:GetAttribute("\083\116\097\116\101")if larm.LocalTransparencyModifier~=0 then visiblearms(true)end if isrunning==true and(includewalksway and(humanoid:GetState()~=Enum.HumanoidStateType.Freefall and humanoid:GetState()~=Enum.HumanoidStateType.Landed))then walksway=walksway:lerp(CFrame.new((.07*swaysize)*math.sin(tick()*((2*humanoid.WalkSpeed)/4)),(.07*swaysize)*math.cos(tick()*((4*humanoid.WalkSpeed)/4)),0)*CFrame.Angles(0,0,(-0.03*swaysize)*math.sin(tick()*((2*humanoid.WalkSpeed)/4))),.2*sensitivity)else walksway=walksway:Lerp(CFrame.new(),.05*sensitivity)end local c=uis:GetMouseDelta()if includecamerasway then sway=sway:Lerp(Vector3.new(c.X,c.Y,c.X/2),.1*sensitivity)end if includestrafe then strafesway=strafesway:Lerp(CFrame.Angles(0,0,-rootpart.CFrame.rightVector:Dot(humanoid.MoveDirection)/(20/swaysize)),.1*sensitivity)end if includejumpsway==true then jumpsway=jumpswaygoal.Value end rightshoulderclone.Transform=rightshoulder.Transform leftshoulderclone.Transform=leftshoulder.Transform if R~=nil and(R=="\067\114\111\117\099\104\105\110\103"and player.Character:FindFirstChildWhichIsA("\084\111\111\108"))then Z=20 end if R~=nil and(R=="\067\114\097\119\108\105\110\103"and player.Character:FindFirstChildWhichIsA("\084\111\111\108"))then Z=80 end local k,u,x=camera.CFrame:ToEulerAnglesYXZ()local I=Vector2.new(math.rad(player.Character.HumanoidRootPart.CFrame.RightVector:Dot((-player.Character.HumanoidRootPart.Velocity*Vector3.new(1,0,1)).Unit)*200),math.rad(player.Character.HumanoidRootPart.CFrame.LookVector:Dot((-player.Character.HumanoidRootPart.Velocity*Vector3.new(1,0,1)).Unit)*200))local s=I.Unit*math.clamp(player.Character.HumanoidRootPart.Velocity.Magnitude/14,0,2)local i=CFrame.new(Vector3.new(camera.CFrame.Position.X,camera.CFrame.Position.Y,camera.CFrame.Position.Z))*CFrame.fromEulerAnglesXYZ(k+math.rad(Z),0,0)local Q,h,L=player.Character.Torso.CFrame.Rotation:ToEulerAnglesXYZ()local n=CFrame.Angles(Q,h,L)local K=CFrame.new()if script.CFrameAimOffset.Value.Position.X~=0 or not(script.CFrameAimOffset.Value.Position.X<=.1)then end local A=((((((((CFrame.new(i.Position)*n)*i.Rotation)*walksway)*jumpsway)*strafesway)*K)*CFrame.Angles(math.rad(sway.Y*swaysize),math.rad(sway.X*swaysize)/10,math.rad(sway.Z*swaysize)/2)+camera.CFrame.UpVector*(-1.7-(headoffset.Y+aimoffset.Value.Y)))+camera.CFrame.LookVector*(headoffset.Z+aimoffset.Value.Z))+camera.CFrame.RightVector*((-headoffset.X-aimoffset.Value.X)+-(sway.X*swaysize)/75)local d=A*script.CFrameAimOffset.Value:Inverse()viewmodel:SetPrimaryPartCFrame(d)end debug.profileend()end)

stepped_con = game:GetService("RunService").RenderStepped:Connect(function()
	debug.profilebegin("FPS")
	swaysize = script.WalkSwayMultiplier.Value


	-- checkfirstperson() checks if camera is first person and enables/disables the viewmodel accordingly
	checkfirstperson()
	-- update loop
	if isfirstperson == true then
		local modifierr = 0
		local statething = player:GetAttribute('State')
		-- make arms visible
		if larm.LocalTransparencyModifier ~= 0 then
			visiblearms(true)
		end
		-- update walk sway if we are walking
		if isrunning == true and includewalksway and humanoid:GetState() ~= Enum.HumanoidStateType.Freefall and humanoid:GetState() ~= Enum.HumanoidStateType.Landed then
			walksway = walksway:lerp(
				CFrame.new(

					(0.07*swaysize) * math.sin(tick() * (2 * humanoid.WalkSpeed/4)),
					(0.07*swaysize) * math.cos(tick() * (4 * humanoid.WalkSpeed/4)),
					0

				)*
					CFrame.Angles(

						0,
						0,
						(-.03*swaysize) * math.sin(tick() * (2 * humanoid.WalkSpeed/4))

					)
				,0.2*sensitivity)
		else
			walksway = walksway:Lerp(CFrame.new(), 0.05*sensitivity)
		end
		--
		local delta = uis:GetMouseDelta()
		--
		if includecamerasway then
			sway = sway:Lerp(Vector3.new(delta.X,delta.Y,delta.X/2), 0.1*sensitivity)
		end
		--
		if includestrafe then
			strafesway = strafesway:Lerp(CFrame.Angles(0,0,-rootpart.CFrame.rightVector:Dot(humanoid.MoveDirection)/(20/swaysize)), 0.1*sensitivity)
		end
		--
		if includejumpsway == true then
			jumpsway = jumpswaygoal.Value
		end
		-- update animation transform for viewmodel
		rightshoulderclone.Transform = rightshoulder.Transform
		leftshoulderclone.Transform = leftshoulder.Transform
		-- cframe the viewmodel

		if statething ~= nil and statething == "Crouching" and player.Character:FindFirstChildWhichIsA("Tool") then
			modifierr = 20
		end

		if statething ~= nil and statething == "Crawling" and player.Character:FindFirstChildWhichIsA("Tool") then
			modifierr = 80
		end

		local CamY, CamX, CamZ = camera.CFrame:ToEulerAnglesYXZ()
		
		local direction = Vector2.new(
			math.rad(player.Character.HumanoidRootPart.CFrame.RightVector:Dot((-player.Character.HumanoidRootPart.Velocity * Vector3.new(1,0,1)).Unit) * 200),
			math.rad(player.Character.HumanoidRootPart.CFrame.LookVector:Dot((-player.Character.HumanoidRootPart.Velocity * Vector3.new(1,0,1)).Unit) * 200)
		)
		
		local tilt = direction.Unit * math.clamp((player.Character.HumanoidRootPart.Velocity.Magnitude / 14), 0, 2)
		
		local firstframe = CFrame.new( Vector3.new(camera.CFrame.Position.X,camera.CFrame.Position.Y,camera.CFrame.Position.Z) ) * CFrame.fromEulerAnglesXYZ(CamY + math.rad(modifierr),0,0)
		local TorsX,TorsY,TorsZ = player.Character.Torso.CFrame.Rotation:ToEulerAnglesXYZ()
		local torsoframe = CFrame.Angles(TorsX,TorsY,TorsZ)
		
		local countercf = CFrame.new()
		

		if script.CFrameAimOffset.Value.Position.X ~= 0 or not (script.CFrameAimOffset.Value.Position.X <= 0.1) then
			--countercf = CFrame.Angles(math.rad(-tilt.Y * 3),math.rad(-tilt.X * 4),math.rad(-tilt.X * 6))
		end 
		
		local finalcf = (CFrame.new(firstframe.Position)*torsoframe*firstframe.Rotation*walksway*jumpsway*strafesway*countercf*CFrame.Angles(math.rad(sway.Y*swaysize),math.rad(sway.X*swaysize)/10,math.rad(sway.Z*swaysize)/2))+(camera.CFrame.UpVector*(-1.7-(headoffset.Y+(aimoffset.Value.Y))))+(camera.CFrame.LookVector*(headoffset.Z+(aimoffset.Value.Z)))+(camera.CFrame.RightVector*(-headoffset.X-(aimoffset.Value.X)+(-(sway.X*swaysize)/75)))
	
		
		local builtcf = finalcf * script.CFrameAimOffset.Value:Inverse()
		
		viewmodel:SetPrimaryPartCFrame(builtcf)
	end
	debug.profileend()
end)

