Is there a way to put a viewport on a brick?

Hi there ive been searching google for a while about putting a viewport frame on a surfaceGUI and i have found not a lot of info about viewports. Am I being dumb or is there actually no way to put one on a brick?

1 Like

yes you can use a surfaceGUI on the brick, the surfacegui has to be in StarterGui, but make the Adornee equal to the brick

2 Likes
-- Create a part to display the viewport on
local part = Instance.new("Part")
part.Size = Vector3.new(5, 5, 1)
part.Position = Vector3.new(0, 5, 0)
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace

-- Add a SurfaceGUI to the part
local surfaceGui = Instance.new("SurfaceGui")
surfaceGui.CanvasSize = Vector2.new(512, 512)
surfaceGui.Parent = part

-- Add a ViewportFrame to the SurfaceGUI
local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = surfaceGui.CanvasSize
viewportFrame.BackgroundTransparency = 1
viewportFrame.Parent = surfaceGui

-- Create a camera and position it
local camera = Instance.new("Camera")
camera.CFrame = CFrame.new(Vector3.new(0, 5, -10), Vector3.new(0, 5, 0))

-- Set the ViewportFrame's Camera property to the camera
viewportFrame.Camera = camera

-- Add a part to display in the viewport
local partInViewport = Instance.new("Part")
partInViewport.Size = Vector3.new(1, 1, 1)
partInViewport.Position = Vector3.new(0, 5, 0)
partInViewport.Anchored = true
partInViewport.CanCollide = false
partInViewport.BrickColor = BrickColor.new("Bright green")
partInViewport.Parent = game.Workspace

-- Run the game and you should see the partInViewport displayed in the viewport on the SurfaceGUI

this wouldnt work, because viewport frame needs to be a child of StarterGui, or PlayerGui

-- Create a ScreenGui to hold the SurfaceGui
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = game.Players.LocalPlayer.PlayerGui

All you need is a SurfaceGui, Adornneed to the BrickPart, and Parented to PlayerGui, no screenGui needed.