Best way to display 2 of the same ViewportFrames Item in a shop GUI?

I am trying to display two of the same VPF in a menu like so:

However I am not sure of the best method to do so, I tried at first to generate two VPF based on the tool provided. It worked, but I think it is not the optimal approach (I have to set items to visible false/true each time and I think it just generates too many VPF for no reason imo).

local toolClone=tool:Clone()
		
		toolClone.Parent = workspace

		toolClone.Parent = Tool.ViewportFrame.WorldModel
		local handle = toolClone:findFirstChild("Handle")
		handle.Anchored = true

		local cam = Instance.new("Camera",Tool.ViewportFrame.WorldModel)

		handle.Position = Vector3.new(0,0,0)

		local maxSize = math.max(handle.Size.X,handle.Size.Y,handle.Size.Z)
		cam.CFrame = CFrame.new(Vector3.new(0,0,maxSize), handle.Position )


		Tool.ViewportFrame.CurrentCamera = cam
		local increment=360/80
		
		coroutine.wrap(function()
		while true do
			for deg=0, 360, increment do
					handle.CFrame=CFrame.new(handle.Position)*CFrame.Angles(math.rad(280),0,math.rad(deg))
				wait()
			end
		end
		end)()
--2nd part is missing because it is redundant, just imagine a copy of the above but where I generate a new VPF for each tool.

My next attempt was to set the Current Camera of the side’s VPF (when player selects an inner menu item) to the inner menu’s item but that didn’t seem to work

function OnItemSelect(Item)
	Side.Item_Buy.Visible=true
	Side.Item_Price.Visible=true
	
	Side.ViewportFrame.CurrentCamera=Item.ViewportFrame.WorldModel.Camera

Any thoughts?

1 Like

Hmm. I am not sure what you mean. However, I do not think it is possible to have two viewport frames with only one object.

I am pretty sure you have to have the object parented to the VPF to display it.

I may not be entirely correct but I think moving the camera is more performant than moving the object.(edit:Yes it is true)Frames | Roblox Creator Documentation

So either make the VPF with all objects inside and separate them from each other and simply move the camera(cleanest) or destroy the VPFs children when you are switching and clone the new part(easiest).

I am not sure which one would be better. Probably the first I would pick.

Also just something small. CFrame.LookAt is better for CFrame.new in this instance.
CFrame.LookAt has an UpVector which you can change if you would like too.

1 Like

Actually I found a solution, thanks for replying though lol I had to figure it out on my own:

So the method I went with was having 1 vpf in the side menu. whenever an Item is selected, destroy whatever contents were in the side vpf (if applicable), then add (and do the necessary scripting to implement) the selected item into the side vpf.

This would repeat every time an item is selected in the inner menu, the previous code above would have 2 sets of VPF (2x for each 1 item) which is unnecessary but at the time I didn’t know how to circumvent it.

I’ll look into CFrame.LookAt whenever I have the time and moving the camera.

1 Like