Anybody good with ViewportFrames on Roblox?

hey!

so what im trying to do is make a system similar to Undertale
im trying to put the character and all the stuff inside of workspace inside of a ViewportFrame
Well, I happened to do tha well, but here’s the problem…



???

heres the script for it:

local viewportFrame = script.Parent 
local camera = workspace.CurrentCamera
camera.Parent = viewportFrame
viewportFrame.CurrentCamera = camera

camera.CFrame = CFrame.new(Vector3.new(0, 10, 0), Vector3.new(0, 0, 0)) 
camera.CameraType = Enum.CameraType.Scriptable

local function updateViewport()
	for _, child in pairs(workspace:GetDescendants()) do
		if child:IsA("BasePart") or child:IsA("Model") and not child:IsA('Terrain') then
			local clone = child:Clone()
			clone.Parent = viewportFrame
		end
	end
end

updateViewport()

workspace.DescendantAdded:Connect(updateViewport)
workspace.DescendantRemoving:Connect(updateViewport)

everything isn’t loading correctly, and i dont know why. Is there any fix to this weird error? If so, please let me know, If your good at ViewportFrames, of course

1 Like

As I know, viewportframe renders anything in low quality.
but you can try:

  • changing Ambient property. Maybe this could be too dark.
  • putting skybox as child of that viewportframe

    This object can use a Sky child as a cubemap for reflections, in which case only the Sky object’s six Skybox[…] properties are used. Assuming these properties are valid, lighting inside the ViewportFrame acts similarly to if Lighting.EnvironmentSpecularScale and Lighting.EnvironmentDiffuseScale are both set to 1

if you need more information, check this and this.

1 Like

Characters can’t be cloned by default, if that’s what you mean by it loading incorrectly.

Set Archivable on the Player’s Character to true before you clone it. It’s a one line fix above where you clone:

child.Archivable = true
local clone = child:Clone()
...

It’s one of those weird quirks with studio that made sense forever ago but doesn’t now.

2 Likes

so…

with the both of you guy’s help, I was able to load all of the contents inside of workspace, with this edited version of the script here (incase yall r curious):

local plr = game:GetService('Players').LocalPlayer
repeat wait() until game:IsLoaded()
local chr = plr.Character or plr.CharacterAdded:Wait()
chr.Archivable = true

local viewportFrame = script.Parent 
local camera = workspace.CurrentCamera
camera.Parent = viewportFrame
viewportFrame.CurrentCamera = camera

camera.CFrame = CFrame.new(Vector3.new(0, 10, 0), Vector3.new(0, 0, 0)) 
camera.CameraType = Enum.CameraType.Scriptable

local function updateViewport()
	repeat wait() until game:IsLoaded()
	for _, child in pairs(workspace:GetChildren()) do
		if child:IsA("Part") or child:IsA("Model") or child:IsA("UnionOperation") or child:IsA("Folder") and not child:IsA('Terrain') and child ~= nil then
			child.Archivable = true
			local clone = child
			task.wait()
			clone.Parent = viewportFrame.WorldModel
		end
	end
	coroutine.resume(coroutine.create(function()
		for _, child in pairs(workspace:GetDescendants()) do
			if child:IsA("Part") or child:IsA("Model") and not child:IsA('Terrain') and child ~= nil then
				child.Archivable = true
				local clone = child
				task.wait()
				clone.Parent = viewportFrame.WorldModel
			end
		end
	end))
end

workspace.DescendantAdded:Connect(updateViewport)
workspace.DescendantRemoving:Connect(updateViewport)

Thank you! now all I need to do now is make the player move inside of the viewportframe, if possible (ima probably need to read the ViewportFrames document again lol) and then boom!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.