Still have questions? Join our Discord server and get real time help.
0

# Why is the view port frame not displaying anything?[SOLVED]

Asked by 9 days ago
Edited 9 days ago

Basically I have two buttons that if you click a gun preview will appear on the viewport. Except it does not display the gun. I have the camera and everything set up and working. I got no errors and I checked to make sure it was going in the viewport and It was.

Here is my code

--August 1 2020
--Test script for the viewport frame
--

---------------
-- Constants --
---------------
local cam = game.Workspace.CurrentCamera
local Guns = game.Workspace.Weapons
local ViewPort = game.Players.LocalPlayer.PlayerGui.ScreenGui.ViewportFrame
local Buttons = game.Players.LocalPlayer.PlayerGui.ScreenGui.GunLables
local ChildrenOfViewport = ViewPort:GetChildren()
---------------------
-- Set Camera type --
---------------------
cam.CameraType = "Scriptable"

-----------------
-- Main script --
-----------------
for i,button in pairs(Buttons:GetChildren()) do
button.MouseButton1Click:Connect(function()
local gunSelected = button.Name
for i,Gun in pairs(Guns:GetChildren()) do
if Gun.Name == gunSelected then
local focus = Gun:FindFirstChild(tostring(Gun.Name) .. "FOC").CFrame
cam.CFrame = focus
local gunClone = Gun:Clone()
gunClone.Parent = ViewPort
end
end
end)
end


Thanks for reading and hopefully answering my question. Sorry if it is an obvious mistake.

EDIT: Silly me I forgot to set the viewport camera. So for anyone who is having the same issue here is what you have to do.

----------------------------
-- Viewport camera --
----------------------------

Viewport.CurrentCamera = The camera you selected


Hope this answer made sense and helped.

0
Sorry it is a very silly mistake that i did not realize. I basically forgot to set the viewport camera. mikey2019d 38 — 9d