Trouble with scripting viewport [SOLVED]

What are you attempting to achieve?

I am attempting to make a view port display a pet model within a Billboard Gui through code.

What is the issue?

I am not getting any errors in the output and am unsure of what i am doing wrong. The model and camera are going into the view-port and the viewport.CurrentCamera is set to the correct camera.

What solutions have you tried so far?

I have tried Countless things. I have tried re positioning the camera, model, and rewriting the code. I have searched the devforum in an attempt to find similar issues and work off of that but have come to no success.

Info

I will provide a screenshot and some code below:

Code
local ModelItem = Database.PetModels:FindFirstChild(GetPets[n].Name):Clone()
			local ViewPortHolder = UIClone.ViewportFrame
			local ViewPort = UIClone.ViewportFrame
			local ViewPortCam = Instance.new("Camera", workspace)
						
			local ViewPortCamPosition = Vector3.new(CoreModule.ViewPortZoomIncrement, CoreModule.ViewPortZoomIncrement, CoreModule.ViewPortZoomIncrement)
			ModelItem.Parent = ViewPortHolder
			ModelItem.PrimaryPart.Position = Vector3.new(0,0,0)
			local ScriptClone = game.ReplicatedStorage.Scripts:FindFirstChild("ItemRotation"):Clone()
			ScriptClone.Parent = ModelItem
			ViewPortCam.Parent = ViewPort
			ViewPort.CurrentCamera = ViewPortCam
			ViewPortCam.CFrame = CFrame.new(ViewPortCamPosition, ModelItem.Build.Body.Position)
			UIClone.ImageColor3 = CoreModule:GetRarityColor(Database.Pets:FindFirstChild(GetPets[n].Name).Rarity.Value)
			GetItems[i].MainBackground.PetFrame.CanvasSize = UDim2.new(0,0,0,GetItems[i].MainBackground.PetFrame.UIGridLayout.AbsoluteContentSize.Y)
			
			for i, v in pairs(ModelItem:GetDescendants()) do
				if v:IsA("Script") then
					v:Destroy()
				elseif v:IsA("BasePart") then
					v.Anchored = true
				end
			end

Again i get no errors, and everything is in the correct place within the View Port Frame.

I am not sure if it is an issue with the CFrame, but i have tried multiple different things for that.

If you have any insights on what to do, or know where the problem is feel free to reply to the thread or DM me.

1 Like

Is your Billboard Gui a descendant of Player Gui?

1 Like

No, it is a descendant a part.
Incubator2

That’s why it’s not working.

Put it under Player Gui and set it’s Adornee to the part.

1 Like

Alright, so far that has fixed the main problem. Although why is only a single part of the model showing?

ViewPort2

Im trying to get an outcome with the viewport showing the whole model.

Picture

This may help with what you are trying to do. Note it will create a viewport frame inside the parent-frame you want. In order for it to show above if you have your GUI ZIndexBehaviour set to Global, I would suggest adding a line where it creates the viewport frame, ZIndex = parentFrame.ZIndex + 1.

I used it for this:
https://gyazo.com/1a561787886c105526a201401cfd7747

If that face is a SurfaceGui, then you’re in trouble. SurfaceGuis can’t be displayed in ViewportFrames. You should replace that with a decal if that is the case.

1 Like

Ok, i will do that, but i still have the problem of only the main part displaying in the view port even though there are multiple parts within the model.

The ears might not be visible from that angle.

EDIT: Oh, and instead of

ModelItem.PrimaryPart.Position = Vector3.new(0,0,0)

Do this:

ModelItem:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0, 0, 0))

Otherwise the rest of the parts in your model won’t move.

They now appear in the view port, although the children of the model, except for the primary part are attached to the camera

Pet2

What other parts are you including in the pet’s model? Remove them or create a model that only contains the pet.

These are all the parts that make up the pet
Pet3
Inside the part above is the decal

1 Like

Mind removing ScriptClone for now and testing this again? It may be messing with your model.

That wasn’t the problem, i just found it. Also that script is deleted when the model is copied.
I added this:

ModelItem:SetPrimaryPartCFrame(CFrame.new(ViewPortCam.CFrame.p, ModelItem.PrimaryPart.Position))

Thank you for all the help!

2 Likes