I tried to make a camera with viewport frame in surface gui but it didn't work, It just spam errors
The script is localscript, Map is a model inside the viewport frame, The script is located on the viewport frame
Script:
local Map = script.Parent:WaitForChild("Map") game:GetService("RunService").RenderStepped:Connect(function() for i, v in pairs(Map:GetChildren()) do v:Destroy() end for i, v in pairs(game.Workspace:GetChildren()) do if v.ClassName ~= "Camera" and v.ClassName ~= "Terrain" then v:Clone().Parent = Map end end end)
Please help.
The reason why your script is erroring is that you're trying to set the parent of EVERYTHING in the workspace, including the player's models, and you can't parent those to a viewport frame unless you make a clone of them.
In order to fix this, you can also make you if statement checks if there is no Humanoid inside of v. If you also want to have the player inside the viewport frame you can make the player's model Archivable property set to true. Setting the Archivable property to true allows the model to be cloned thus allowing you to parent it to the Map.
local Map = script.Parent:WaitForChild("Map") game:GetService("RunService").RenderStepped:Connect(function() for i, v in pairs(Map:GetChildren()) do v:Destroy() end for i, v in pairs(game.Workspace:GetChildren()) do print(v) if v.ClassName ~= "Camera" and v.ClassName ~= "Terrain" and not v:FindFirstChildOfClass("Humanoid") then v:Clone().Parent = Map end end end)