Viewportframe, help!

I am trying to use viewportframes to make an animation preview for an emote shop, but i’m struggling with it.

This is the script i’m using, this is just the viewportframe and character part:

local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0.3, 0, 0.4, 0)
viewportFrame.Position = UDim2.new(0, 15, 0, 15)
viewportFrame.BackgroundColor3 = Color3.new(0.196078, 0.196078, 0.196078)
viewportFrame.BorderSizePixel = 0
viewportFrame.Parent = script.Parent

local clone = game.Players.LocalPlayer.Character:Clone()
clone.Parent = viewportFrame

local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame

viewportCamera.CFrame = CFrame.new(Vector3.new(20, 20, 20), clone.HumanoidRootPart.Position)

This is the issue i’m having:

image

So there’s two things i need to do:

  1. Fix the cloning issue
  2. Make the animation play in the clone

I would appreciate a lot any help, thanks!

1 Like

Try waiting for the character before cloning it.
Like this:

local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local clone = Character:Clone()
-- Rest of the code
1 Like

Changed the code, it still shows the same error.

1 Like

Maybe that’s because the clone fell of the word. Try setting the HumanoidRootPart of the clone to a position that he isn’t going to die. :thinking:

1 Like
local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0.3, 0, 0.4, 0)
viewportFrame.Position = UDim2.new(0, 15, 0, 15)
viewportFrame.BackgroundColor3 = Color3.new(0.196078, 0.196078, 0.196078)
viewportFrame.BorderSizePixel = 0
viewportFrame.Parent = script.Parent

local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local clone = Character:Clone()
clone.HumanoidRootPart.Position = Vector3.new(-80.67, 0.5, -244.88)

clone.Parent = viewportFrame

local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame

viewportCamera.CFrame = CFrame.new(Vector3.new(0, 0, 10), clone.HumanoidRootPart.Position)

Same error.

I’ll try your code in my game, just a moment…

1 Like

Ok, so I did some tests, and for some reason you can’t clone the player character.
I tried do clone other models and it works perfectly fine, but if I try to clone the player character it gives me an error.
I found this post, and this may help you: Can’t clone character?
But, when I set the property Archivable to true it just clones the Character model, not the descendants of the model.
So, at this point, I don’t know what to do. :frowning:

2 Likes

Instead i can use a dummy then.

1 Like

Yes, I think you could try it!
This is a great idea.

1 Like

I tried using a dummy yesterday, but i had some problems with the camera angle, and that’s happening again.

local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0.3, 0, 0.4, 0)
viewportFrame.Position = UDim2.new(0, 15, 0, 15)
viewportFrame.BackgroundColor3 = Color3.new(0.196078, 0.196078, 0.196078)
viewportFrame.BorderSizePixel = 0
viewportFrame.Parent = script.Parent

local Character = game.ReplicatedStorage.Dummy
local clone = Character:Clone()

clone.Parent = viewportFrame

local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame

viewportCamera.CFrame = CFrame.new(Vector3.new(0, 0, 10), clone.HumanoidRootPart.Position)

It did in fact work but this is the result:

image

Use this?

clone.Position = Vector3.new(0, 0, 10)

I’ll try that, but wouldn’t that go wrong because it’s a model and it doesn’t have a Position property

So, this?

clone:SetPrimaryCFrame(Vector3.new(0, 0, 10))

To fix that, I just moved the dummy to the spawn.

The reason you have the problem is that a player’s character cannot be cloned because the Archivable property is set to false on default. To clone it, you need to set the archivable property to true:

local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0.3, 0, 0.4, 0)
viewportFrame.Position = UDim2.new(0, 15, 0, 15)
viewportFrame.BackgroundColor3 = Color3.new(0.196078, 0.196078, 0.196078)
viewportFrame.BorderSizePixel = 0
viewportFrame.Parent = script.Parent

local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
char.Archivable = true
local clone = char:Clone()
char.Archivable = false
clone.Parent = viewportFrame

local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame

viewportCamera.CFrame = CFrame.new(Vector3.new(20, 20, 20), clone.HumanoidRootPart.Position)
1 Like

I already did this, but it just clones the character model, not the descendants.

1 Like

Well that looks like it works… kinda.

image

And if you want you can rotate it to, so it looks to the camera.

1 Like

Maybe this?

local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0.3, 0, 0.4, 0)
viewportFrame.Position = UDim2.new(0, 15, 0, 15)
viewportFrame.BackgroundColor3 = Color3.new(0.196078, 0.196078, 0.196078)
viewportFrame.BorderSizePixel = 0
viewportFrame.Parent = script.Parent

local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
char.Archivable = true
for _, object in pairs(char:GetDescendants()) do
	object.Archivable = true
end
local clone = char:Clone()
for _, object in pairs(char:GetDescendants()) do
	object.Archivable = false
end
char.Archivable = false
clone.Parent = viewportFrame

local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame

viewportCamera.CFrame = CFrame.new(Vector3.new(20, 20, 20), clone.HumanoidRootPart.Position)

I think this is happening because you set the camera CFrame to 0,0,0.
If you want you can set it to the Dummy HumanoidRootPart position + Vector.new(0,0,10)

1 Like