Walk breaking when i change CameraSubject

When i change CameraSubject and changing it back to humanoid walking animation breaking and i want to know if there is possible way to fix this

Here you can see what happening when i change camera subject back to humanoid

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, IsTyping)
	if IsTyping then
		return
	end
	if input.KeyCode == Enum.KeyCode.F and game.Players.LocalPlayer.PlayerGui.Button.Enabled == true and game.Players.LocalPlayer.PlayerGui.Button.TextLabel.Text == "F" then
		workspace[game.Players.LocalPlayer.Name].HumanoidRootPart.Anchored = true
		workspace[game.Players.LocalPlayer.Name].HumanoidRootPart.CFrame = game.Players.LocalPlayer.PlayerGui.Button.TextLabel.pos.Value
		workspace[game.Players.LocalPlayer.Name].Humanoid:LoadAnimation(game.ReplicatedStorage.WhenWalkOrIdle):Play()
		game.Workspace.CurrentCamera.CameraSubject = workspace[game.Players.LocalPlayer.Name].Torso
		wait(2.93)
		workspace[game.Players.LocalPlayer.Name].HumanoidRootPart.CFrame = game.Players.LocalPlayer.PlayerGui.Button.TextLabel.pos2.Value
		workspace[game.Players.LocalPlayer.Name].HumanoidRootPart.Anchored = false
		game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
		game.Workspace.CurrentCamera.CameraSubject = workspace[game.Players.LocalPlayer.Name].Humanoid
	end
end)

Thanks for helping