--Update Camera Pos after Phys Update

RS.Heartbeat:Connect(function()
	if Mode == 1 then
		if UIS.MouseBehavior ~= Enum.MouseBehavior.Default and Camera.CameraType ~= Enum.CameraType.Custom then
			UIS.MouseBehavior = Enum.MouseBehavior.Default
			Camera.CameraType = Enum.CameraType.Custom
		end
	elseif Mode == 2 then
		UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
		Camera.CameraType = Enum.CameraType.Scriptable
		local LookDelta = UIS:GetMouseDelta()
		local X = Look.X - LookDelta.Y*Sensitivity
		Look = Vector2.new((X >= MaxLook and MaxLook) or (X <= -MaxLook and -MaxLook) or X,
			(Look.Y - LookDelta.X*Sensitivity) % 360)
		
		Camera.CFrame = CFrame.new(HRP.Position + CamOffset)
			* CFrame.Angles(0,math.rad(Look.Y),0)
			* CFrame.Angles(math.rad(Look.X),0,0)
	end
end)

UIS.InputBegan:Connect(function(input)
	--Swap Between First and Third Person and Lock the Mouse
	if input.KeyCode == FPSLock then
		if Mode == 1 then
			Mode = 2
			HidePlayer()
		else
			Mode = 1
			ShowPlayer()
		end
	end
end)

Player.CharacterAdded:Connect(CharacterRespawn)
