-
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. -
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:
-
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.