Duplicate player character jumping in a viewport frame

So I have this code

local player = game.Players.LocalPlayer
local character = player.Character
character:WaitForChild("HumanoidRootPart")

character.Archivable = true
local DuplicateCharacter = character:Clone()
for _, item in pairs(DuplicateCharacter:GetChildren()) do
	if item:IsA("Script") or item:IsA("LocalScript") then
		item:Destroy()
	end
end
DuplicateCharacter.Humanoid.PlatformStand = true
DuplicateCharacter.Humanoid.AutoJumpEnabled = false
character.Archivable = false
DuplicateCharacter:WaitForChild("HumanoidRootPart")
DuplicateCharacter:SetPrimaryPartCFrame(game.Workspace.PlayerOutfitRenderer.PlayerCharacterPosition.CFrame)
DuplicateCharacter.Parent = viewPort

Most of the times this works perfectly and there is just the player character but sometimes the character is in the jumping/falling animation. I’ve already tried removing the scripts and everything but nothing works. How can I fix this?