How to get a player to show up using GetPartBoundsInBox?

Hi, I’m trying to create a camera system and I use GetPartBoundsInBox to get all the parts within the area I want the camera to see (Im using a viewport frame) but I ran into a problem that I am unsure how to fix.

Whenever a player is within the area none of the accessories or head is copied into the viewport.

Screenshot 2024-07-29 194658

Is there a way to fix this?

Heres the code.

local Gui = script.Parent
local Camera = workspace.Cameras.Camera1
local ViewportCamera = Instance.new("Camera")
local Screen = Camera.Screen
local DetectZone = Camera.DetectZone

ViewportCamera.CFrame = Screen.CFrame
Gui.ViewportFrame.CurrentCamera = ViewportCamera

while true do
	wait(.6)
	ViewportCamera.CFrame = Screen.CFrame
	local parts = workspace:GetPartBoundsInBox(DetectZone.CFrame,DetectZone.Size)
	local OldParts = Gui.ViewportFrame:GetChildren()
	for _, part in OldParts do
		part:Destroy()
	end
	
	for _, part in parts do
		local Clone = part:Clone()
		Clone.Parent = Gui.ViewportFrame
	end
end

I think you have to add a WorldModel inside the viewport frame so that it can support humanoids

1 Like

I tried but it still shows the same thing on the viewport. Maybe Im using it wrong?

local Gui = script.Parent
local Camera = workspace.Cameras.Camera1
local ViewportCamera = Instance.new("Camera")
local Screen = Camera.Screen
local DetectZone = Camera.DetectZone

ViewportCamera.CFrame = Screen.CFrame
Gui.ViewportFrame.CurrentCamera = ViewportCamera

while true do
	wait(.6)
	ViewportCamera.CFrame = Screen.CFrame
	local parts = workspace:GetPartBoundsInBox(DetectZone.CFrame,DetectZone.Size)
	local OldParts = Gui.ViewportFrame.WorldModel:GetChildren()
	for _, part in OldParts do
		part:Destroy()
	end
	
	for _, part in parts do
		local Clone = part:Clone()
		Clone.Parent = Gui.ViewportFrame.WorldModel
	end
end