I am trying to make a script that has a camera in the world and copys/removes the folder in the viewportframe but it keeps on erroring if it tries to change the parent of a cloned part
Players.EnderPowerHD.PlayerGui.SurfaceGui.LocalScript:20: attempt to index nil with 'Parent'
/\ The Error
/ My Local Script
game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)
local camera = Instance.new("Camera")
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = game.Workspace.Cam.CFrame
script.Parent.ViewportFrame.CurrentCamera = camera
while true do
script.Parent.ViewportFrame.Folder:Destroy()
local folder = Instance.new("Folder")
folder.Parent = script.Parent.ViewportFrame
local world = game.Workspace:GetChildren()
for i = 1,#world do
if world[i]:IsA("Terrain") == false then
if world[i]:IsA("Camera") == false then
if world[i] ~= nil then
local part = world[i]:Clone()
part.Parent = folder
end
end
end
end
wait(1)
end

3 comments
These 2 are the exact same just that i used an for loop (It gives the same error even with the part of the codes exchanged)
Im testing that out, why do you have a surface gui on the players gui?
you have to have it in the player guit or else you cant see it you can only adornee it to a part