Help with ViewportFrame

Hey,
Thanks for Clicking on my Post!
I am Making A "Pet Inventory" Where When you open an Egg, the Pet goes into your Inventory
and is Displayed in A ViewportFrame.

I Cannot Figure Out what I did Wrong
But When I Set the Pet to be inside the ViewportFrame,

It Looks Like this
Its A Grey Spot (Pet Colour Is Grey)

image_2021-08-03_131544

The Script I Use is

local newPet = Pet:Clone()
newPet.Parent = TemplateClone.petImage.ViewportFrame
	
local petCamera = Instance.new("Camera")
petCamera.CFrame = CFrame.new(newPet.Body.Position - (-newPet.Body.CFrame.LookVector * 3.2),newPet.Body.Position) 
petCamera.Parent = TemplateClone.petImage.ViewportFrame
	
TemplateClone.petImage.ViewportFrame.CurrentCamera = petCamera

Thanks for Reading! :happy1:

1 Like

Try this:

local function getLargestSize(part)
    local sizetable = {part.Size.X,part.Size.Y,part.Size.Z}
    local largestsize
    for i,v in pairs(sizetable) do
        if largestsize == nil then
            largestsize = v
        else
            if v > largestsize then
                largestsize = v
            end
        end
    end
    return largestsize
end

local newPet = Pet:Clone()
newPet.Parent = TemplateClone.petImage.ViewportFrame
local largestPetSize = getLargestSize(newPet.Body)

local petCamera = Instance.new("Camera")
petCamera.CFrame = CFrame.new(newPet.Body.Position + Vector3.new(largestPetSize,largestPetSize,largestPetSize),newPet.Body.Position) 
petCamera.Parent = TemplateClone.petImage.ViewportFrame
	
TemplateClone.petImage.ViewportFrame.CurrentCamera = petCamera

thats what i did to make my viewport frame inventory work

1 Like

image It works
But the Pet is Rotated Weirdly

let me know if this works

local function getLargestSize(part)
    local sizetable = {part.Size.X,part.Size.Y,part.Size.Z}
    local largestsize
    for i,v in pairs(sizetable) do
        if largestsize == nil then
            largestsize = v
        else
            if v > largestsize then
                largestsize = v
            end
        end
    end
    return largestsize
end

local newPet = Pet:Clone()
newPet.Parent = TemplateClone.petImage.ViewportFrame
local largestPetSize = getLargestSize(newPet.Body)

local petCamera = Instance.new("Camera")
petCamera.CFrame = CFrame.new(newPet.Body.Position + Vector3.new(0,-largestPetSize,0),newPet.Body.Position) 
petCamera.Parent = TemplateClone.petImage.ViewportFrame
	
TemplateClone.petImage.ViewportFrame.CurrentCamera = petCamera
1 Like

image
This is what happens

well, you just gotta play around with the camera position. here is my last guess

local function getLargestSize(part)
    local sizetable = {part.Size.X,part.Size.Y,part.Size.Z}
    local largestsize
    for i,v in pairs(sizetable) do
        if largestsize == nil then
            largestsize = v
        else
            if v > largestsize then
                largestsize = v
            end
        end
    end
    return largestsize
end

local newPet = Pet:Clone()
newPet.Parent = TemplateClone.petImage.ViewportFrame
local largestPetSize = getLargestSize(newPet.Body)

local petCamera = Instance.new("Camera")
petCamera.CFrame = CFrame.new(newPet.Body.Position + Vector3.new(-largestPetSize,largestPetSize,largestPetSize),newPet.Body.Position) 
petCamera.Parent = TemplateClone.petImage.ViewportFrame
	
TemplateClone.petImage.ViewportFrame.CurrentCamera = petCamera
1 Like

Hey, I Finnaly Made the Pet face the Correct way,
The issue is that it Is Pretty Small In the ViewportFrame.

Could you help me with this?

image

local function getLargestSize(part)
	local sizetable = {part.Size.X,part.Size.Y,part.Size.Z}
	local largestsize
	for i,v in pairs(sizetable) do
		if largestsize == nil then
			largestsize = v
		else
			if v > largestsize then
				largestsize = v
			end
		end
	end
	return largestsize
end

function addToInventory(Pet)
	local PlayerGUI = game.Players.LocalPlayer.PlayerGui
	local SidebarGUI = PlayerGUI:FindFirstChild("Sidebars")
	local InventoryFrame = SidebarGUI.GroupOne.PetStuff.MainPetFrame.PetList
	
	local Template = InventoryFrame.Layout:FindFirstChild("petTemplate")
	
	local TemplateClone = Template:Clone()
	TemplateClone.Name = Pet.Name .. "s Template"
	TemplateClone.Parent = InventoryFrame
	
	local newPet = Pet:Clone()
	newPet.Parent = TemplateClone.petImage.ViewportFrame
	local largestPetSize = getLargestSize(newPet.Body)

	local petCamera = Instance.new("Camera")
	petCamera.CFrame = CFrame.new(newPet.Body.Position + Vector3.new(-largestPetSize - 12,largestPetSize,-largestPetSize + 5),newPet.Body.Position) 
	petCamera.Parent = TemplateClone.petImage.ViewportFrame

	TemplateClone.petImage.ViewportFrame.CurrentCamera = petCamera
end

yea i guess we could just shorten the camera distance a bit, also sorry for the late answer, i was asleep

local function getLargestSize(part)
	local sizetable = {part.Size.X,part.Size.Y,part.Size.Z}
	local largestsize
	for i,v in pairs(sizetable) do
		if largestsize == nil then
			largestsize = v
		else
			if v > largestsize then
				largestsize = v
			end
		end
	end
	return largestsize
end

function addToInventory(Pet)
	local PlayerGUI = game.Players.LocalPlayer.PlayerGui
	local SidebarGUI = PlayerGUI:FindFirstChild("Sidebars")
	local InventoryFrame = SidebarGUI.GroupOne.PetStuff.MainPetFrame.PetList
	
	local Template = InventoryFrame.Layout:FindFirstChild("petTemplate")
	
	local TemplateClone = Template:Clone()
	TemplateClone.Name = Pet.Name .. "s Template"
	TemplateClone.Parent = InventoryFrame
	
	local newPet = Pet:Clone()
	newPet.Parent = TemplateClone.petImage.ViewportFrame
	local largestPetSize = getLargestSize(newPet.Body)

	local petCamera = Instance.new("Camera")
	petCamera.CFrame = CFrame.new(newPet.Body.Position + Vector3.new(-largestPetSize*0.75,largestPetSize*0.75,-largestPetSize*0.75),newPet.Body.Position) 
	petCamera.Parent = TemplateClone.petImage.ViewportFrame

	TemplateClone.petImage.ViewportFrame.CurrentCamera = petCamera
end
1 Like