ViewportFrame subjects too small, due to bad camera configuration

Hi!

A quick issue with Viewport frames, is the subject is too small.
The code:

local function AddGUIs()
	for i, v in pairs(Module) do

		local SomeConstant = 5
		Print("InPairs for AddGUI Started")
		local NewVPF = Instance.new("ViewportFrame")
		NewVPF.BackgroundColor3 = Color3.fromRGB(255,255,255)
		NewVPF.BackgroundTransparency = 1
		NewVPF.Name = i
		NewVPF.Parent = loc
		local Item = game.ReplicatedStorage.Assets.Data.Furniture[i]:Clone()
		Item.Parent = NewVPF
		local Cam = Instance.new("Camera")
		Cam.Parent = NewVPF
		Cam.CameraSubject = Item
		NewVPF.CurrentCamera = Cam
--There's an error on this line		Cam.CFrame = CFrame.new(v.PrimaryPart.CFrame.Position + (v.PrimaryPart.CFrame.LookVector * SomeConstant ), v.PrimaryPart.Position)
		Cam.Focus = CFrame.new(0,0,Module[i].CameraPan)
		local SelectButton = Instance.new("TextButton")
		SelectButton.Text = ""
		SelectButton.Font = Enum.Font.Gotham
		SelectButton.TextColor3 = Color3.fromHSV(0, 0, 1)
		SelectButton.BackgroundTransparency = 0.999
		SelectButton.Size = UDim2.new(1,0,1,0)
		SelectButton.Parent = NewVPF
		SelectButton.Name = "Select"
		local NewCorner = Instance.new("UICorner")
		NewCorner.Parent = NewVPF
		NewCorner.CornerRadius = UDim.new(0.15,0)
		Print("Created ViewportFrame, SelectButton, and Corner, success, instance string instance, "..i.."/??"..ModuleAmount)
	end
	loaded = true
end

The sisue MIGHT be I need the CFrame, but I commented out the line, because it was causing issues.
Result:
image

Thanks for any help!

You probably have to set the CFrame, yeah.

You don’t need to set the CameraSubject or the Focus.

Your CFrame line looks okay to me. What’s the error you get?

CFrame is not a valid member of Camera, I think,. I’m readding it right now to get an accurate response.

image

Here’s the error.

Could you send the specific line of code? Along with any variable definitions that are being used at that time?

Here’s the line. On line 440 I have

local SomeConstant = 5
		Cam.CFrame = CFrame.new(v.PrimaryPart.CFrame.Position + (v.PrimaryPart.CFrame.LookVector * SomeConstant ), v.PrimaryPart.Position)

Could be that v doesn’t have a PrimaryPart, so when you do v.PrimaryPart.CFrame it’s complaining

If it’s a normal Mesh or part, doesn’t the script know that the PrimaryPart is the only part?

Well, I don’t know what Module is, but PrimaryPart is something for Models.

It also doesn’t make much sense to me why you’re cloning game.ReplicatedStorage.Assets.Data.Furniture[i] but then basing the Camera CFrame off of v. Are these supposed to be the same thing?

I dont really know why I did that looking back over it, and I will probably change it.


Also, making a solution I got this.

You probably meant v.

i is just a number that represents the index into the Module table.

v is the entry in that table itself.

1 Like

yeah i did, sorry i’m an idiot and it’s 11:30

1 Like

Still using v:IsA( I got a nil value.
This is an example entry for an item in my table.

Data.Template = {
	DisplayName = "Template Item"
	Model = ItemsFolder:WaitForChild("Item")
	DisplayModel = Model
	CameraRot = Vector3.new(0,0,0);
	CameraPan = 4;
	PlacementType = "ItemType";
	Price = 10
	SellPercent = 85; --85 = furniture, 80 = seasonal, 75 construction item
	Description = "This is a template item, make sure to change most of it!";
	Categories = {"All", "CHANGE_THIS", "CHANGE_THIS,", "etc"};
	Item = true;
	HasImage = false;
	ImageNumber = 0;
}

Well, yeah, there’s no IsA in that table. There’s also no CFrame in there.

I was operating under the assumption that Module was full of actual Instances, not custom objects.

You’ll need to access the actual parts in that table like v.DisplayModel.CFrame or v.DisplayModel:IsA. I’m not sure exactly because I don’t know what all these things mean to you


Now I have this, meaning it’s working, but I dont have CameraPan or CameraRotation implemented yet.

local function AddGUIs()
	for i, v in pairs(Module) do

		local SomeConstant = 5
		Print("InPairs for AddGUI Started")
		local NewVPF = Instance.new("ViewportFrame")
		NewVPF.BackgroundColor3 = Color3.fromRGB(255,255,255)
		NewVPF.BackgroundTransparency = 1
		NewVPF.Name = i
		NewVPF.Parent = loc
		local Item = game.ReplicatedStorage.Assets.Data.Furniture[i]:Clone()
		Item.Parent = NewVPF
		local Cam = Instance.new("Camera")
		Cam.Parent = NewVPF
		Cam.CameraSubject = Item
		NewVPF.CurrentCamera = Cam
		if v.Model:IsA("Model") then
			Cam.CFrame = CFrame.new(v.Model.PrimaryPart.CFrame.Position + (v.Model.PrimaryPart.CFrame.LookVector * SomeConstant ), v.Model.PrimaryPart.Position)
		else
			Cam.CFrame = CFrame.new(v.Model.CFrame.Position + (v.Model.CFrame.LookVector * SomeConstant ), v.Model.Position)	
		end
		Cam.Focus = CFrame.new(0,0,Module[i].CameraPan)
		local SelectButton = Instance.new("TextButton")
		SelectButton.Text = ""
		SelectButton.Font = Enum.Font.Gotham
		SelectButton.TextColor3 = Color3.fromHSV(0, 0, 1)
		SelectButton.BackgroundTransparency = 0.999
		SelectButton.Size = UDim2.new(1,0,1,0)
		SelectButton.Parent = NewVPF
		SelectButton.Name = "Select"
		local NewCorner = Instance.new("UICorner")
		NewCorner.Parent = NewVPF
		NewCorner.CornerRadius = UDim.new(0.15,0)
		Print("Created ViewportFrame, SelectButton, and Corner, success, instance string instance, "..i.."/??"..ModuleAmount)
	end
	loaded = true
end

1 Like

Nice! Sorry, were you asking a question or is this thread solved?

It’s half working, look at the output, there’s an error on the model side. My guess is it tried to add a model, but I have an error with that.

I don’t know what line that error is referring to, and I don’t know what your data looks like.

Try using the lua debugger to step through your code line-by-line and inspect what all the variables are at each line. That might help you to find your bug/find what is nil when you expect it to be not-nil.

The error is on the line that’s dealing with the CFrame of Models.