Viewport Frame not showing Pet Model!

I want my Viewport Frame to show my Pet Model.

My Viewport Frame is not showing my Pet Model

I’ve looked at the Roblox Developer Forum, and have looked at some videos explaining Viewport Frames, I’ve also used AI, but it cannot find the problem.

My pet has a PrimaryPart, it’s name is “Body”
The Viewport Frame CurrentCamera is set to the Camera inside of the Viewport.
The Viewport Sizing is the 1,0,1,0 (in other words same size as its parent Frame)

This is a part of the function that handles the Viewport Frame showing.

			for _, Pet in pairs(Pets) do
		local PetEgg = PetsFolder:FindFirstChild(ClosestEgg.Name)
		local PetModel = PetEgg:FindFirstChild(Pet.Name)
		local PetTemplate = MainFrame:FindFirstChild(Pet.Name)
		if PetModel then
			if not PetTemplate then
				PetTemplate = PetTemplates.Template:Clone()
				PetTemplate.Parent = MainFrame
				PetTemplate.Name = Pet.Name
				
				local ChanceLabel = PetTemplate:FindFirstChild("Chance")
				ChanceLabel.Text = tostring(Pet.Chance) .. "%"
				ChanceLabel.TextColor3 = RarityColors[Pet.Rarity] or Color3.new(1, 1, 1)
				
				-- VIEWPORT FRAME RELATED 
				local ViewportFrame = PetTemplate:FindFirstChild("ViewportFrame")
				
				local PetClone = PetModel:Clone()
				local PetPrimary = PetClone.PrimaryPart or PetClone:FindFirstChild("Body")
				local PrimaryPosition = PetPrimary.Position
				PetClone.Parent = ViewportFrame
				
				local ViewportCamera = Instance.new("Camera")
				ViewportCamera.Name = (PetModel.Name.."Camera")
				ViewportCamera.Parent = ViewportFrame
				
				local CameraPosition = PrimaryPosition + Vector3.new(0, 0, 12)
				local ViewingPosition = PrimaryPosition
				
				ViewportFrame.CurrentCamera = ViewportCamera
				ViewportFrame.CurrentCamera.CFrame = CFrame.new(CameraPosition, ViewingPosition)
				
				-- DEBUGGING PRINTS
				print("PetClone:", PetClone.Name)
				print("PrimaryPart:", PetPrimary.Name)
				print("PrimaryPart Position:", PetPrimary.Position)
				print("CameraPosition:", CameraPosition)
				print("ViewportFrame Size:", ViewportFrame.Size)
				print("Camera CFrame:", ViewportCamera.CFrame)
			end
		else
			warn("Pet model not found for: " .. Pet.Name)
		end
		InRange(BillboardClone)
	end
end

Here is a screenshot of my Workspace, and the issue.


image

I would appreciate any help / feedback that you could give me!

If you have any questions, I would be happy to reply.

I’ve done some more experimenting, but I can’t find what’s wrong.
Everything seems to be correct. I even made a different script just to test it.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Template = script.Parent

local ViewportFrame = Instance.new("ViewportFrame")
ViewportFrame.Name = "ViewportFrame"
ViewportFrame.Parent = Template
ViewportFrame.Size = UDim2.new(1, 0, 1, 0)
ViewportFrame.BackgroundTransparency = 1

local Camera = Instance.new("Camera")
Camera.Name = "PetCamera"
Camera.Parent = ViewportFrame

local PetFolder = ReplicatedStorage:FindFirstChild("Pets")
local EggFolder = PetFolder:WaitForChild("Basic Egg")
local Pet = EggFolder:FindFirstChild("Bunny")

if Pet then
	local PetClone = Pet:Clone()  -- Clone the pet model
	PetClone.Parent = ViewportFrame

	local PrimaryPart = PetClone.PrimaryPart or PetClone:FindFirstChild("Body")

	if PrimaryPart then
		local PrimaryPosition = PrimaryPart.Position

		-- Adjust the camera position and look at the pet
		local CameraPosition = PrimaryPosition + Vector3.new(0, 2, 12)
		local LookAtPosition = PrimaryPosition

		ViewportFrame.CurrentCamera = Camera
		ViewportFrame.CurrentCamera.CFrame = CFrame.new(CameraPosition, LookAtPosition)
	else
		warn("Primary part not found for pet model")
	end
else
	warn("Couldn't find pet")
end

Heres the ViewportFrame with that btw.
image

1 Like

Boost, Since I still haven’t gotten help! I’ve tried a ton of things!