How can i do this with viewport frames?

I want to make viewport frames with the correspending models in the frame, but im not sure how to make the camera face them
this is the replicated storage folder for the models


this is the viewport frame being cloned for each new character

this is the script for cloning the frames

i’ve might’ve not added enough context, so please tell me if i need to

1 Like

CFrame.lookAt
There is more optimized way to do that btw but this should be enough for you.
Also please avoid using anonimous functions like in your example unless its a closure.
You also should not use ipairs and pairs anymore as since it does slow down the perfomance and is complitelly unneeded in your example
Also chars :GetChildren() could be cached in outside scope so you be able to loop dirrectly through that.
Not sure why you are putting it inside a function anyway

Please stop saying “don’t use ipairs and pairs” (they’re still very much relevant), it does not impact performance in any way unless you completely disable compiler optimizations manually.

If I’m understanding your question correctly, you want to make the camera of the viewport face the models?

You should be able to just set a constant camera CFrame and move the models to a specific position in the viewport, unless you’re planning to have models of different sizes, in which case, you should look into something like ViewportFrame Model Fitter.

yes, i want to make it so each viewport camera faces their corresponding model, and the models will all be the same size
how could i be able to add a constant camera cframe?

If ipairs and pairs arent needed anymore, what should i use instead?
and im putting it in a function since im going to be using it somewhere else in the script as well and i want to keep it organised

A camera is needed if you want to change the perspective of the viewport, do you have one in the viewportframe?

Screenshot 2025-06-02 221528
yeah i do
(the character inside is just a template/placeholder)


Change the CFrame of the camera to where you want it.

I did that already with the placeholder, but i dont know how i can put the models in the replicated storage in the placeholders position to make it face them instead of it

You can implicitly iterate over tables by just not using an iterator function like this (and personally I do prefer to do this as well):

for k, v in t do

end

This has the same behavior as pairs, but you don’t need to not use it.

If you’re trying to move the models, look into using PVInstance:PivotTo().

I tried using it, and it still gave me the same problem am i doing something wrong?

[grid]


it still only shows the placeholders model

it parents to the characterframe, but the new model doesnt show

this is the script, i moved the model to the cframe of the placeholder but it doesnt show

Can you say what exactly is the problem?

it still shows the placeholder model only, the other models are different from it

Can you show the code related to reparenting/cloning/etc?

do you mean the part of the script responsible for cloning the buttons?

What is char.GUI.DisplayCharacter.Character?

char is the character folder for each character in the character folder

How are you putting them into the viewport to display it?