Why is this viewport frame not working?

It’s my first time trying with viewport frame, it will display a part
image
image

the script:

local part = Instance.new("Part",script.Parent.ViewportFrame)
local vpf = script.Parent.ViewportFrame
local runservice = game:GetService("RunService")
local cam = Instance.new("Camera",vpf)
vpf.CurrentCamera = cam

runservice.RenderStepped:Connect(function()
    if part ~= nil then
        cam.CFrame = part.CFrame + Vector3.new(5,5,5)
        cam.CFrame = CFrame.lookAt(cam.CFrame.Position,part.Position)
        vpf.CurrentCamera = cam
    end
end)

why it don’t work

2 Likes

Hmm, I really don’t know try double check the script for some errors just play inside the game and press F9 to check.

1 Like

I checked it, no error is printed neither it works

Can you send me the GUI in a message? I will check for you.

how to send gui in a message? how to do it

Or else try to turn your place into a file and sent it to me

ViewportTest.rbxl (24.6 KB)

ok i sent

3 Likes

The camera should be parented to the viewportframe

1 Like

oh! i did not know it sorry i thought i can be anywhere

Yep, that really helped fixed it.

wait isnt it in the viewport frame?

No it was not their I think you forgot to put it.

local vpf = script.Parent.ViewportFrame
local runservice = game:GetService("RunService")
local cam = Instance.new("Camera",vpf)

uh? its in viewport frame?

1 Like

I test your script and its still work fine for me

1 Like

check the link i sent, why it don’t work in my game

no? it works in your game the script then why not in my game to, thats why u said

Yeah I know but now its broken again…

I don’t know why is it doing that.

uh? its broken in your game? so the viewport frame property is working sometimes? no right

Yeah first it fixed it and its broken again for some reason…