Using viewportframe

This is my first time using a viewport frame. My goal is to make it so you can preview animations before you buy them in an emote shop.

This is the script i have so far:

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.ReplicatedStorage.Dummy: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)

image

Result:

image

I need help to fix the camera position and add the animation part, i would really appreciate help.

PS: If easy to do i would like to use the player’s character instead of a dummy.
Thanks! :slightly_smiling_face:

Change the position of the dummy and make it closer to the camera.
What position is the camera at right now?

To make the dummy the players character you could clone the players character and put it in the viewport frame.

clone.HumanoidRootPart.Position = Vector3.new(0,0,-5)

I tried doing that but it said that the clone.Parent was nil

This is the current camera position i think

Edit: Afk

1 Like

Change the Vector3 in there to

Vector3.new(0,0,10) -- Mess around with the z axis to change its distance.
viewportCamera.CFrame = CFrame.new(Vector3.new(0, 0, 10), clone.HumanoidRootPart.Position)

I’ll mess around with it a bit to find the best angle, in the meanwhile how would i do the animation part?

local animation = clone.Humanoid:LoadAnimation(animation)
animation:Play()