Viewport Frame issue

I created a script where my pets would be display inside of a viewportFrame. The pets are currently in the Replicated Storage inside a folder called PetsToDisplay. The problem is that the system works but… the pets aren’t align properly within the viewportFrame. Here is the script. I want it so that the pets would individual correspond with the viewportFrame size, but with only one script. How could I achieve this?

Client Script

--// Services
local RunService = game:GetService('RunService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')

--// Variables
local camera = Instance.new('Camera')
local rotation = 0
local speed = 1


for i, v in pairs(script.Parent:WaitForChild('ScrollingFrame'):GetChildren()) do
	if v:IsA('Frame') and v.Name ~= 'Template' then
		local pets = ReplicatedStorage:WaitForChild('PetsToDisplay'):FindFirstChild(v.Name)
		local viewportFrame = v:FindFirstChild('ViewportFrame')
		pets.Parent = viewportFrame
		camera.Parent = viewportFrame
		viewportFrame.CurrentCamera = camera

		RunService.RenderStepped:Connect(function()
			local cframe = pets.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(rotation), 0) * CFrame.new(0, 0, -5)
			cframe = CFrame.new(cframe.p, pets.PrimaryPart.Position)
			camera.CFrame = cframe
			rotation += speed
		end)
	end
end

This problem is still an issue and I havent figured out the reason why yet…

Is this in a script or local script?

So basically the pets aren’t showing up correctly? And theres no errors?

Edit: You’re using different ViewportFrame sizes? If so, that’s going to give you a lot more headache. You might need to manually adjust the position of the camera in each one of those ViewportFrames.

Cameras do not replicated so they must be created on the client.

Everything is created on the client.

Are you creating a viewportframe where the camera circles around the pet?

No errors, and instead of my pets showing in front of the camera like usual, its making the pets zoom out farther,

The viewportFrame is already there. I just parent the pet to it and create a camera. Look at the script above

Try setting the CFrame to CFrame.new(0,0,3), you need to play around with values to the best you want it.

New CFrame: Pets.PrimaryPart.CFrame * CFrame.new(0,0,3)

Wouldnt that effect everything since I am using a for loop in this case?

It would only affect the camera that is inside the viewportframe

so would the line be like this?

cframe = CFrame.new(CFrame.new(0,0,3,), pets.PrimaryPart.Position)

and also I am creating a camera inside each viewportFrame. So the camera cframe would affect the viewport view aswell correct?

Try Pets.PrimaryPart.CFrame * CFrame.new(0,0,3) instead.

It doesnt rotate and the pets still are zoomed out.

You’re creating multiple RunService.RenderStepped inside a for loop and it might be stacking on top of each other.

No I am not creating multiple. I am using one SteppedEvent and its sort of adds to the loop I placed in.

I was thinking of parenting the pets Size with the viewport Frame but that didnt work either

If you want the camera to rotate. You can do so by using RunService and adding a degree with CFrame.Angles (remember, CFrame.Angles is in radians)

I am already using RunService for this.