function AimGun()if(Camera.CoordinateFrame.p-Camera.Focus.p).magnitude>1 or Reloading or Knifing or ThrowingGrenade then return end local A=(Gui_Clone:WaitForChild("\083\099\111\112\101")):WaitForChild("\073\109\103")local x=(Gui_Clone:WaitForChild("\083\099\111\112\101")):WaitForChild("\083\116\101\097\100\121")Aimed=true Aiming=true CurrentRecoil=S.Recoil.Aimed CurrentSpread=S.Spread.Aimed Gui_Clone.CrossHair.Box:TweenSizeAndPosition(UDim2.new(),UDim2.new(),Enum.EasingDirection.Out,Enum.EasingStyle.Sine,S.AimAnimation and S.AimSpeed or 0,true)if S.AimAnimation then local x=Camera.FieldOfView local v=Humanoid.CameraOffset local M=A.BackgroundTransparency TweenJoint(LWeld,ArmC0[1],S.ArmC1_Aimed.Left,Sine,S.AimSpeed)TweenJoint(RWeld,ArmC0[2],S.ArmC1_Aimed.Right,Sine,S.AimSpeed)TweenJoint(AnimWeld,CF(0,1,0),CF(),Sine,S.AimSpeed)TweenJoint(Grip,Grip.C0,Aimed_GripCF,Sine,S.AimSpeed)TweenJoint(LWeld2,CF(),CF(),Sine,S.AimSpeed)TweenJoint(RWeld2,CF(),CF(),Sine,S.AimSpeed)local Q=0 while true do local v=Q+1.5/S.AimSpeed Q=v>90 and 90 or v if not Aimed then break end if not Selected then break end local B=1-COS(RAD(Q))Camera.FieldOfView=NumLerp(x,S.MaxZoom,B)if S.GuiScope then A.BackgroundTransparency=NumLerp(M,0,B)end if Q==90 then break end RS:wait()end else LWeld.C0,LWeld.C1=ArmC0[1],S.ArmC1_Aimed.Left RWeld.C0,RWeld.C1=ArmC0[2],S.ArmC1_Aimed.Right AnimWeld.C0=CF(0,1,0)Grip.C1=Aimed_GripCF LWeld2.C1,RWeld2.C1=CF(),CF()Camera.FieldOfView=S.MaxZoom end Aiming=not Aimed if not Aiming and S.GuiScope then spawn(function()x.Visible=true A.BackgroundTransparency=1 A.ImageTransparency=0 local S=Instance.new("\077\111\100\101\108")S.Name="\071\117\110\095\077\111\100\101\108"for A,x in pairs(Gun:GetChildren())do if x:IsA("\066\097\115\101\080\097\114\116")then local A=x:Clone()A.Parent=S local v=Instance.new("\087\101\108\100")v.Part0=A v.Part1=x v.Parent=A local M=Instance.new("\078\117\109\098\101\114\086\097\108\117\101")M.Name="\080\114\101\118\084\114\097\110\115"M.Value=x.Transparency M.Parent=x x.Transparency=1 end end S.Parent=Character end)spawn(function()while Aimed do local A=CameraSteady and 0 or Idleing and AnimAng[2]or AnimAng[4]if CameraSway~=0 then local x,v=0,0 if Idleing then x=(((RAD(COS((A*5)*CameraSway^.4))/40)*CameraSway^1.2)*StanceSway)*S.ScopeSway v=(((RAD(COS((A*2)*CameraSway^.4))/40)*CameraSway^1.2)*StanceSway)*S.ScopeSway else x=(((RAD(COS(((A*3)/2)*CameraSway^.4))/25)*CameraSway^1.2)*StanceSway)*S.ScopeSway v=(((RAD(COS(((A*3)/5)*CameraSway^.4))/25)*CameraSway^1.2)*StanceSway)*S.ScopeSway end RotCamera(x,v)end RS:wait()end end)end end function UnAimGun(A)local x=(Gui_Clone:WaitForChild("\083\099\111\112\101")):WaitForChild("\073\109\103")local v=(Gui_Clone:WaitForChild("\083\099\111\112\101")):WaitForChild("\083\116\101\097\100\121")if not A then if not Aimed then return end if Reloading and A or Knifing and not ThrowingGrenade then return end CurrentRecoil=S.Recoil.Hipfire CurrentSpread=(Idleing and not Walking)and S.Spread.Hipfire or S.Spread.Walking if Walking and Aimed then Gui_Clone.CrossHair.Box:TweenSizeAndPosition(UDim2.new(0,150,0,150),UDim2.new(0,-75,0,-75),Enum.EasingDirection.Out,Enum.EasingStyle.Linear,S.AimAnimation and S.AimSpeed or 0,true)elseif Idleing then Gui_Clone.CrossHair.Box:TweenSizeAndPosition(UDim2.new(0,70,0,70),UDim2.new(0,-35,0,-35),Enum.EasingDirection.Out,Enum.EasingStyle.Linear,S.AimAnimation and S.AimSpeed or 0,true)end Aimed=false Aiming=true if S.GuiScope then spawn(function()local A=Character:FindFirstChild("\071\117\110\095\077\111\100\101\108")if A then A:Destroy()end for A,S in pairs(Gun:GetChildren())do if S:IsA("\066\097\115\101\080\097\114\116")then local A=S:FindFirstChild("\080\114\101\118\084\114\097\110\115")S.Transparency=A.Value A:Destroy()end end end)end if S.AimAnimation then local A=Camera.FieldOfView local M=Humanoid.CameraOffset local Q=x.BackgroundTransparency==1 and(S.GuiScope and 0 or 1)or x.BackgroundTransparency x.ImageTransparency=1 v.Visible=false TweenJoint(LWeld,ArmC0[1],S.ArmC1_UnAimed.Left,Sine,S.AimSpeed)TweenJoint(RWeld,ArmC0[2],S.ArmC1_UnAimed.Right,Sine,S.AimSpeed)TweenJoint(Grip,Grip.C0,CFANG(0,RAD(20),0),Sine,S.AimSpeed)if S.PlayerAnimations then TweenJoint(LWeld2,CF(),CFANG(0,RAD(ArmTilt),0),Sine,S.AimSpeed)TweenJoint(RWeld2,CF(),CFANG(0,RAD(ArmTilt),0),Sine,S.AimSpeed)end local B=0 while true do local v=B+1.5/S.AimSpeed B=v>90 and 90 or v if Aimed then break end if not Selected then break end local M=1-COS(RAD(B))Camera.FieldOfView=NumLerp(A,90,M)x.BackgroundTransparency=NumLerp(Q,1,M)if B==90 then break end RS:wait()end else x.BackgroundTransparency=1 x.ImageTransparency=1 v.Visible=false LWeld.C0,LWeld.C1=ArmC0[1],S.ArmC1_UnAimed.Left RWeld.C0,RWeld.C1=ArmC0[2],S.ArmC1_UnAimed.Right Grip.C1=CFANG(0,RAD(20),0)LWeld2.C1,RWeld2.C1=CFANG(0,RAD(ArmTilt),0),CFANG(0,RAD(ArmTilt),0)Camera.FieldOfView=90 end Aiming=Aimed else if S.GuiScope then spawn(function()local A=Character:FindFirstChild("\071\117\110\095\077\111\100\101\108")if A then A:Destroy()end for A,S in pairs(Gun:GetChildren())do if S:IsA("\066\097\115\101\080\097\114\116")then local A=S:FindFirstChild("\080\114\101\118\084\114\097\110\115")S.Transparency=A.Value A:Destroy()end end end)end spawn(function()Aimed=false Aiming=false CurrentRecoil=S.Recoil.Hipfire CurrentSpread=(Idleing and not Walking)and S.Spread.Hipfire or S.Spread.Walking if not Walking then Gui_Clone.CrossHair.Box:TweenSizeAndPosition(UDim2.new(0,70,0,70),UDim2.new(0,-35,0,-35),Enum.EasingDirection.Out,Enum.EasingStyle.Linear,S.AimAnimation and S.AimSpeed or 0,true)else Gui_Clone.CrossHair.Box:TweenSizeAndPosition(UDim2.new(0,150,0,150),UDim2.new(0,-75,0,-75),Enum.EasingDirection.Out,Enum.EasingStyle.Linear,S.AimAnimation and S.AimSpeed or 0,true)end local A=Camera.FieldOfView local M=Humanoid.CameraOffset local Q=x.BackgroundTransparency==1 and(S.GuiScope and 0 or 1)or x.BackgroundTransparency x.ImageTransparency=1 v.Visible=false if LWeld:FindFirstChild("\084\119\101\101\110\067\111\100\101")then LWeld.TweenCode:Destroy()end if RWeld:FindFirstChild("\084\119\101\101\110\067\111\100\101")then RWeld.TweenCode:Destroy()end if Grip:FindFirstChild("\084\119\101\101\110\067\111\100\101")then Grip.TweenCode:Destroy()end if LWeld2:FindFirstChild("\084\119\101\101\110\067\111\100\101")then LWeld2.TweenCode:Destroy()end if RWeld2:FindFirstChild("\084\119\101\101\110\067\111\100\101")then RWeld2.TweenCode:Destroy()end if S.AimAnimation then local v=0 while true do local M=v+1.5/S.AimSpeed v=M>90 and 90 or M if Aimed then break end if not Selected then break end local B=1-COS(RAD(v))Camera.FieldOfView=NumLerp(A,90,B)x.BackgroundTransparency=NumLerp(Q,1,B)if v==90 then break end RS:wait()end else x.BackgroundTransparency=1 x.ImageTransparency=1 v.Visible=false Camera.FieldOfView=90 end end)end end


function AimGun()
	if (Camera.CoordinateFrame.p - Camera.Focus.p).magnitude > 1 or Reloading or Knifing or ThrowingGrenade then return end
	local Scope = Gui_Clone:WaitForChild("Scope"):WaitForChild("Img")
	local Steady = Gui_Clone:WaitForChild("Scope"):WaitForChild("Steady")
	Aimed = true
	Aiming = true
	CurrentRecoil = S.Recoil.Aimed
	CurrentSpread = S.Spread.Aimed
	Gui_Clone.CrossHair.Box:TweenSizeAndPosition(
		UDim2.new(),
		UDim2.new(),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		S.AimAnimation and S.AimSpeed or 0,
		true
	)
	if S.AimAnimation then
		local CurrentFOV = Camera.FieldOfView
		local CurrentCameraOffset = Humanoid.CameraOffset
		local CurrentTrans = Scope.BackgroundTransparency
		TweenJoint(LWeld, ArmC0[1], S.ArmC1_Aimed.Left, Sine, S.AimSpeed)
		TweenJoint(RWeld, ArmC0[2], S.ArmC1_Aimed.Right, Sine, S.AimSpeed)
		TweenJoint(AnimWeld, CF(0, 1, 0), CF(), Sine, S.AimSpeed)
		TweenJoint(Grip, Grip.C0, Aimed_GripCF, Sine, S.AimSpeed)
		TweenJoint(LWeld2, CF(), CF(), Sine, S.AimSpeed)
		TweenJoint(RWeld2, CF(), CF(), Sine, S.AimSpeed)
		local X = 0
		while true do
			local NewX = X + 1.5 / S.AimSpeed
			X = (NewX > 90 and 90 or NewX)
			if (not Aimed) then break end
			if (not Selected) then break end
			local Alpha = 1 - COS(RAD(X))
			Camera.FieldOfView = NumLerp(CurrentFOV, S.MaxZoom, Alpha)
			if S.GuiScope then
				Scope.BackgroundTransparency = NumLerp(CurrentTrans, 0, Alpha)
			end
			if X == 90 then break end
			RS:wait()
		end
	else
		LWeld.C0, LWeld.C1 = ArmC0[1], S.ArmC1_Aimed.Left
		RWeld.C0, RWeld.C1 = ArmC0[2], S.ArmC1_Aimed.Right
		AnimWeld.C0 = CF(0, 1, 0)
		Grip.C1 = Aimed_GripCF
		LWeld2.C1, RWeld2.C1 = CF(), CF()
		Camera.FieldOfView = S.MaxZoom
	end
	Aiming = (not Aimed)
	if (not Aiming) and S.GuiScope then
		spawn(function()
			Steady.Visible = true
			Scope.BackgroundTransparency = 1
			Scope.ImageTransparency = 0
			
			local Gun_Model = Instance.new("Model")
			Gun_Model.Name = "Gun_Model"
			for _, Obj in pairs(Gun:GetChildren()) do
				if Obj:IsA("BasePart") then
					local ObjClone = Obj:Clone()
					ObjClone.Parent = Gun_Model
					
					local W = Instance.new("Weld")
					W.Part0 = ObjClone
					W.Part1 = Obj
					W.Parent = ObjClone
					
					local PrevTrans = Instance.new("NumberValue")
					PrevTrans.Name = "PrevTrans"
					PrevTrans.Value = Obj.Transparency
					PrevTrans.Parent = Obj
					
					Obj.Transparency = 1
				end
			end
			Gun_Model.Parent = Character
		end)
		spawn(function()
			while Aimed do
				local Ang = (CameraSteady and 0 or (Idleing and AnimAng[2] or AnimAng[4]))
				if CameraSway ~= 0 then
					local OffsetX, OffsetY = 0, 0
					if Idleing then
						OffsetX = (RAD(COS(Ang * 5 * (CameraSway ^ 0.4))) / 40) * (CameraSway ^ 1.2) * StanceSway * S.ScopeSway
						OffsetY = (RAD(COS(Ang * 2 * (CameraSway ^ 0.4))) / 40) * (CameraSway ^ 1.2) * StanceSway * S.ScopeSway
					else
						OffsetX = (RAD(COS(Ang * 3/2 * (CameraSway ^ 0.4))) / 25) * (CameraSway ^ 1.2) * StanceSway * S.ScopeSway
						OffsetY = (RAD(COS(Ang * 3/5 * (CameraSway ^ 0.4))) / 25) * (CameraSway ^ 1.2) * StanceSway * S.ScopeSway
					end
					RotCamera(OffsetX, OffsetY)
				end
				RS:wait()
			end
		end)
	end
end

function UnAimGun(Exception)
	local Scope = Gui_Clone:WaitForChild("Scope"):WaitForChild("Img")
	local Steady = Gui_Clone:WaitForChild("Scope"):WaitForChild("Steady")
	if (not Exception) then
		if (not Aimed) then return end
		if (Reloading and Exception) or Knifing and (not ThrowingGrenade) then return end
		CurrentRecoil = S.Recoil.Hipfire
		CurrentSpread = ((Idleing and (not Walking)) and S.Spread.Hipfire or S.Spread.Walking)
		if Walking and Aimed then
			Gui_Clone.CrossHair.Box:TweenSizeAndPosition(
				UDim2.new(0, 150, 0, 150),
				UDim2.new(0, -75, 0, -75),
				Enum.EasingDirection.Out,
				Enum.EasingStyle.Linear,
				S.AimAnimation and S.AimSpeed or 0,
				true
			)
		elseif Idleing then
			Gui_Clone.CrossHair.Box:TweenSizeAndPosition(
				UDim2.new(0, 70, 0, 70),
				UDim2.new(0, -35, 0, -35),
				Enum.EasingDirection.Out,
				Enum.EasingStyle.Linear,
				S.AimAnimation and S.AimSpeed or 0,
				true
			)
		end
		Aimed = false
		Aiming = true
		if S.GuiScope then
			spawn(function()
				local Gun_Model = Character:FindFirstChild("Gun_Model")
				if Gun_Model then
					Gun_Model:Destroy()
				end
				
				for _, Obj in pairs(Gun:GetChildren()) do
					if Obj:IsA("BasePart") then
						local PrevTrans = Obj:FindFirstChild("PrevTrans")
						
						Obj.Transparency = PrevTrans.Value
						PrevTrans:Destroy()
					end
				end
			end)
		end
		if S.AimAnimation then
			local CurrentFOV = Camera.FieldOfView
			local CurrentCameraOffset = Humanoid.CameraOffset
			local CurrentTrans = (Scope.BackgroundTransparency == 1 and (S.GuiScope and 0 or 1) or Scope.BackgroundTransparency)
			Scope.ImageTransparency = 1
			Steady.Visible = false
			TweenJoint(LWeld, ArmC0[1], S.ArmC1_UnAimed.Left, Sine, S.AimSpeed)
			TweenJoint(RWeld, ArmC0[2], S.ArmC1_UnAimed.Right, Sine, S.AimSpeed)
			TweenJoint(Grip, Grip.C0, CFANG(0, RAD(20), 0), Sine, S.AimSpeed)
			if S.PlayerAnimations then
				TweenJoint(LWeld2, CF(), CFANG(0, RAD(ArmTilt), 0), Sine, S.AimSpeed)
				TweenJoint(RWeld2, CF(), CFANG(0, RAD(ArmTilt), 0), Sine, S.AimSpeed)
			end
			local X = 0
			while true do
				local NewX = X + 1.5 / S.AimSpeed
				X = (NewX > 90 and 90 or NewX)
				if Aimed then break end
				if (not Selected) then break end
				local Alpha = 1 - COS(RAD(X))
				Camera.FieldOfView = NumLerp(CurrentFOV, 90, Alpha)
				Scope.BackgroundTransparency = NumLerp(CurrentTrans, 1, Alpha)
				if X == 90 then break end
				RS:wait()
			end
		else
			Scope.BackgroundTransparency = 1
			Scope.ImageTransparency = 1
			Steady.Visible = false
			LWeld.C0, LWeld.C1 = ArmC0[1], S.ArmC1_UnAimed.Left
			RWeld.C0, RWeld.C1 = ArmC0[2], S.ArmC1_UnAimed.Right
			Grip.C1 = CFANG(0, RAD(20), 0)
			LWeld2.C1, RWeld2.C1 = CFANG(0, RAD(ArmTilt), 0), CFANG(0, RAD(ArmTilt), 0)
			Camera.FieldOfView = 90
		end
		Aiming = Aimed
	else
		if S.GuiScope then
			spawn(function()
				local Gun_Model = Character:FindFirstChild("Gun_Model")
				if Gun_Model then
					Gun_Model:Destroy()
				end
				
				for _, Obj in pairs(Gun:GetChildren()) do
					if Obj:IsA("BasePart") then
						local PrevTrans = Obj:FindFirstChild("PrevTrans")
						
						Obj.Transparency = PrevTrans.Value
						PrevTrans:Destroy()
					end
				end
			end)
		end
		spawn(function()
			Aimed = false
			Aiming = false
			CurrentRecoil = S.Recoil.Hipfire
			CurrentSpread = ((Idleing and (not Walking)) and S.Spread.Hipfire or S.Spread.Walking)
			if (not Walking) then
				Gui_Clone.CrossHair.Box:TweenSizeAndPosition(
					UDim2.new(0, 70, 0, 70),
					UDim2.new(0, -35, 0, -35),
					Enum.EasingDirection.Out,
					Enum.EasingStyle.Linear,
					S.AimAnimation and S.AimSpeed or 0,
					true
				)
			else
				Gui_Clone.CrossHair.Box:TweenSizeAndPosition(
					UDim2.new(0, 150, 0, 150),
					UDim2.new(0, -75, 0, -75),
					Enum.EasingDirection.Out,
					Enum.EasingStyle.Linear,
					S.AimAnimation and S.AimSpeed or 0,
					true
				)
			end
			local CurrentFOV = Camera.FieldOfView
			local CurrentCameraOffset = Humanoid.CameraOffset
			local CurrentTrans = (Scope.BackgroundTransparency == 1 and (S.GuiScope and 0 or 1) or Scope.BackgroundTransparency)
			Scope.ImageTransparency = 1
			Steady.Visible = false
			if LWeld:FindFirstChild("TweenCode") then LWeld.TweenCode:Destroy() end
			if RWeld:FindFirstChild("TweenCode") then RWeld.TweenCode:Destroy() end
			if Grip:FindFirstChild("TweenCode") then Grip.TweenCode:Destroy() end
			if LWeld2:FindFirstChild("TweenCode") then LWeld2.TweenCode:Destroy() end
			if RWeld2:FindFirstChild("TweenCode") then RWeld2.TweenCode:Destroy() end
			if S.AimAnimation then
				local X = 0
				while true do
					local NewX = X + 1.5 / S.AimSpeed
					X = (NewX > 90 and 90 or NewX)
					if Aimed then break end
					if (not Selected) then break end
					local Alpha = 1 - COS(RAD(X))
					Camera.FieldOfView = NumLerp(CurrentFOV, 90, Alpha)
					Scope.BackgroundTransparency = NumLerp(CurrentTrans, 1, Alpha)
					if X == 90 then break end
					RS:wait()
				end
			else
				Scope.BackgroundTransparency = 1
				Scope.ImageTransparency = 1
				Steady.Visible = false
				Camera.FieldOfView = 90
			end
		end)
	end
end
