Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Part becomes way to big to fit camera?

So i'm trying to make a explosion of confetti when you buy something and to make it go over the guis I need to turn the gui into a surface gui that is right in-front of the camera. However what if the player is playing on a massive screen or a tiny one.. How do I get the size of the camera in studs.. I have tried to get pixels to studs but there is no accurate way to do that..

Heres my code but as you can see the part becomes WAY to big.

script.Parent.TextButton.MouseButton1Click:connect(function()
    local studsizeX = game.Workspace.CurrentCamera.ViewportSize.X/13
    local studsizeY = game.Workspace.CurrentCamera.ViewportSize.Y/13

    local part1 = workspace.CamPart
    local part2 = workspace.CamPart2

    part1.Size = Vector3.new(studsizeX,studsizeY,1)
    part2.Size = Vector3.new(studsizeX,studsizeY,1.1)

    local Camera = game.Workspace.CurrentCamera

    part1.CFrame = Camera.CFrame + Camera.CFrame.LookVector * Vector3.new(0,0,0.5)
    part2.CFrame = Camera.CFrame + Camera.CFrame.LookVector * Vector3.new(0,0,0.45)

    script.Parent.Enabled = false
    for i,x in pairs(script.Parent:GetChildren()) do
        x:Clone().Parent = workspace.CamPart.SurfaceGui
    end
    wait(0.2)

    for i,x in pairs(workspace.CamPart2:GetChildren()) do
        x.Enabled = true
    end

    wait(0.4)

    for i,x in pairs(workspace.CamPart2:GetChildren()) do
        x.Enabled = false
    end
end)

1 answer

You can't get a camera size in studs. That simply doesn't make sense.

If you have a part that is 1x1x1 studs, it could take up your entire screen or it could be a little pixel on your screen depending on how far away it is from the camera. This means you can't measure a camera in studs because there are an infinite amount of part sizes that could take up the size of your screen.

However, you could get the studs required to fill a certain amount of pixels by using some math (view frustum equations).

I hope that can help you out a bit :)

This discussion is preserved as it was. New answers, comments, and votes are closed.