Placing Part Behind UI

  1. What do you want to achieve?
    I am trying to place a part behind a GUI frame, but I don’t really know what I’m doing. I’ve followed some code samples posted in another topic; however, it’s still not quite right.

  2. What is the issue?
    Currently, the part’s size and position is slightly off, and facing the wrong direction. It should be positioned behind the white frame, and sized to cover the entire background of the frame:
    image

  3. What solutions have you tried so far?
    Here’s the code I’m currently using to achieve this, based on the following code excerpts: devforum.roblox.com/t/dynamic-way-to-cover-the-users-screen-with-a-brick/26244

local RenderStepped = game:GetService 'RunService'.RenderStepped
local Frame = script.Parent

local Part = Instance.new 'Part'
Part.Anchored = true
Part.Transparency = .1
Part.Color = Color3.new(1, 0, 0)
Part.Material = Enum.Material.Ice
Part.CanCollide = false
Part.CastShadow = false

RenderStepped:Connect(function()
	local Camera = workspace.CurrentCamera
	local CamCF = Camera.CFrame
	
	local TopLeft = CamCF:pointToObjectSpace(Camera:ViewportPointToRay(Frame.AbsolutePosition.X, 0, 0).Origin)
	local TopRight = CamCF:pointToObjectSpace(Camera:ViewportPointToRay(Frame.AbsolutePosition.X + Frame.AbsoluteSize.X, 0, 0).Origin)
	local BottomLeft = CamCF:pointToObjectSpace(Camera:ViewportPointToRay(0, Frame.AbsoluteSize.Y, 0).Origin)
	
	local SizeX = TopRight.x - TopLeft.x
	local SizeY = BottomLeft.y - TopLeft.y
	local SizeVector = Vector3.new(SizeX, SizeY, .2)
	
	local Position = Frame.AbsolutePosition + Frame.AbsoluteSize / 2
	
	Part.Size = SizeVector
	Part.CFrame = CFrame.new(Camera:ScreenPointToRay(Position.X, Position.Y, .2).Origin)
end)

Part.Parent = workspace

Any help or tips would be appreciated, as I’m not great with manipulation of parts or maths in general lol.

1 Like

Ideally, I’d like to have maybe a glass part behind a frame so that it creates a magnified effect behind the UI. Unfortunately, ViewportFrames do not interact with the workspace.

1 Like

How people used to do this before ViewportFrames were made is that they would add a local BillboardGui as the background UI for the part since the local UI will always be above the part.

So basically remove that portion of the UI and add a BillboardGui behind the part if you do not want to use a ViewportFrame.