How can I make a screenshot system?

Hey! Currently, I’m working on a screenshot system. To do this, I tried to get all the objects in my screen, and put them inside of a viewportframe.

Here’s the code:

script.Parent.MouseButton1Click:Connect(
    function()
        local function hasProperty(object, prop)
            local t = object[prop] 
        end

        for i, v in pairs(workspace:GetDescendants()) do
            local success =
                pcall(
                function()
                    hasProperty(v, "Position")
                end
            )

            if success then
                local vis = workspace.CurrentCamera:WorldToScreenPoint(v.Position)

                if vis and not v:IsA("Terrain") and not v:IsA("Attachment") then
                    v:Clone().Parent = game.Players.LocalPlayer.PlayerGui.ScreenGui.ViewportFrame
                end
            end
        end
    end
)

It sort of works, but this is all it does:

Screen Shot 2020-09-13 at 1.48.58 PM

How can I fix this?

1 Like

Did you set up the camera correctly?

Have you tried inserting a WorldModel into the viewport, then anchoring the cloned part, then parenting the clone to the worldmodel instead?

How will I know if I set it up properly?

The camera CFrame should be the same as the CurrentCamera’s CFrame for a screenshot system I’d assume

Tried that, didn’t work.
Screen Shot 2020-09-13 at 2.38.38 PM

Code:

script.Parent.MouseButton1Click:Connect(
    function()
        local function hasProperty(object, prop)
            local t = object[prop]
        end

        for i, v in pairs(workspace:GetChildren()) do
            local success =
                pcall(
                function()
                    hasProperty(v, "Position")
                end
            )

            if success then
                local vis = workspace.CurrentCamera:WorldToScreenPoint(v.Position)

                if vis then
                    for i, des in pairs(v:GetDescendants()) do
                        local success2 =
                            pcall(
                            function()
                                hasProperty(v, "Anchored")
                            end
                        )

                        if success2 then
                            des.Anchored = true
                            v:Clone().Parent = game.Players.LocalPlayer.PlayerGui.ScreenGui.ViewportFrame.WorldModel
                        end
                    end
                end
            end
        end
    end
)

Screen Shot 2020-09-13 at 2.40.23 PM

I only have 1 camera, is that the problem?

No, set the CFrame of the camera inside of the ViewportFrame to the CurrentCamera CFrame.