ViewportFrame

Show Deprecated

ViewportFrame is a GuiObject that can render 3D objects inside its bounds, offering a way to display 3D objects in a 2D space like a ScreenGui. This object has the following caveats:

Code Samples

ViewportFrame - Create GUI

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = playerGui
local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0.3, 0, 0.4, 0)
viewportFrame.Position = UDim2.new(0, 15, 0, 15)
viewportFrame.BackgroundColor3 = Color3.new(0, 0, 0)
viewportFrame.BorderColor3 = Color3.new(0.6, 0.5, 0.4)
viewportFrame.BorderSizePixel = 2
viewportFrame.BackgroundTransparency = 0.25
viewportFrame.Parent = screenGui
local part = Instance.new("Part")
part.Material = Enum.Material.Concrete
part.Color = Color3.new(0.25, 0.75, 1)
part.Position = Vector3.new(0, 0, 0)
part.Parent = viewportFrame
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame
viewportCamera.CFrame = CFrame.new(Vector3.new(0, 2, 12), part.Position)
ViewportFrame - Control Camera

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = playerGui
local TweenService = game:GetService("TweenService")
local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0.3, 0, 0.4, 0)
viewportFrame.Position = UDim2.new(0, 15, 0, 15)
viewportFrame.BackgroundColor3 = Color3.new(0, 0, 0)
viewportFrame.BorderColor3 = Color3.new(0.6, 0.5, 0.4)
viewportFrame.BorderSizePixel = 2
viewportFrame.BackgroundTransparency = 0.25
viewportFrame.Parent = screenGui
local part = Instance.new("Part")
part.Material = Enum.Material.Concrete
part.Color = Color3.new(0.25, 0.75, 1)
part.Position = Vector3.new(0, 0, 0)
part.Parent = viewportFrame
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame
viewportCamera.CFrame = CFrame.new(Vector3.new(0, 2, 12), part.Position)
task.wait(2)
local cameraGoal = {
CFrame = CFrame.new(Vector3.new(0, 6, 4), part.Position),
}
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local tween = TweenService:Create(viewportCamera, tweenInfo, cameraGoal)
tween:Play()

Summary

Properties

Properties inherited from GuiObjectProperties inherited from GuiBase2d

Methods

Methods inherited from GuiObject

Events

Events inherited from GuiObjectEvents inherited from GuiBase2d

Properties

Ambient

Read Parallel

This property determines the lighting hue applied to the area within the ViewportFrame. Defaults to Color3.fromRGB(200, 200, 200) (ghost grey).

CurrentCamera

Not Replicated
Read Parallel

Camera instance that is used to render children objects. Defaults to nil.

The Camera object does not replicate so the ViewportFrame.CurrentCamera won't replicate either. When you set this property, Camera.CFrame and Camera.FieldOfView will be saved and replicate with ViewportFrame internally so the client can render the frame without a Camera object.

ImageColor3

Read Parallel

This property determines how a rendered image will be colorized, allowing you to change the image color without directly modifying the rendered object. The default colorization value is Color3.new(1, 1, 1) (white) at which no color modification occurs.

See also ImageTransparency which determines the transparency of the rendered image.

ImageTransparency

Read Parallel

This property determines the transparency of the rendered image, allowing you to change the image transparency without directly modifying the rendered object. A value of 0 (default) is completely opaque and a value of 1 is completely transparent (invisible).

See also ImageColor3 which determines how a rendered image will be colorized.

LightColor

Read Parallel

The color of the emitted light. Defaults to Color3.fromRGB(140, 140, 140) (silver).

LightDirection

Read Parallel

A Vector3 representing the direction of the light source from position Vector3.new(0, 0, 0). Defaults to Vector3.new(-1, -1, -1).

Methods

Events