Print every 3d object that can be seen in the gui

I have been confused on how would I print every 3d object that can be seen in the green gui? I tried searching for a topic the same but nothing pops up. Having trouble looking for a formula, is there a formula for this already?

You can use AbsoluteSize and AbsolutePosition to make some calculations and get the corners and the check if the Part position to screen is inside the Frame.

wait(4) --
--Offset to scale
--OffsetRatio = 0.00128
local camera = workspace.CurrentCamera
local Visible = {}
local Frame = script.Parent.Parent.Frame

--Corner Position Calculation
--[[local FullPosToOffset = Frame.AbsolutePosition
local FullScaleToOffset = Frame.AbsoluteSize
print(FullPosToOffset, FullScaleToOffset)
local TopLeftCornerPos = Vector2.new(FullPosToOffset.X - FullScaleToOffset.X, FullPosToOffset.Y + FullScaleToOffset.Y)
local TopRightCornerPos = Vector2.new(FullPosToOffset.X + FullScaleToOffset.X, FullPosToOffset.Y + FullScaleToOffset.Y)
local BottomLeftCornerPos = Vector2.new(FullPosToOffset.X - FullScaleToOffset.X, FullPosToOffset.Y - FullScaleToOffset.Y)
local BottomRightCornerPos = Vector2.new(FullPosToOffset.X + FullScaleToOffset.X, FullPosToOffset.Y - FullScaleToOffset.Y)
print(TopLeftCornerPos, TopRightCornerPos)]]
script.Parent.MouseButton1Click:Connect(function()
	local FullPosToOffset = Frame.AbsolutePosition
	local FullScaleToOffset = Frame.AbsoluteSize
	print(FullPosToOffset, FullScaleToOffset)
	local TopLeftCornerPos = Vector2.new(FullPosToOffset.X --[[- FullScaleToOffset.X]], FullPosToOffset.Y--[[ + FullScaleToOffset.Y]])
	local TopRightCornerPos = Vector2.new(FullPosToOffset.X + FullScaleToOffset.X, FullPosToOffset.Y --[[+ FullScaleToOffset.Y]])
	local BottomLeftCornerPos = Vector2.new(FullPosToOffset.X --[[- FullScaleToOffset.X]], FullPosToOffset.Y + FullScaleToOffset.Y)
	local BottomRightCornerPos = Vector2.new(FullPosToOffset.X + FullScaleToOffset.X, FullPosToOffset.Y + FullScaleToOffset.Y)
	print(TopLeftCornerPos, TopRightCornerPos)
	for i,v in pairs(workspace:GetChildren()) do
		if v:IsA("Part") then
			WTSP = camera:WorldToScreenPoint(v.Position)
			WTSPVec2 = Vector2.new(WTSP.X, WTSP.Y)
			if TopLeftCornerPos.X <= WTSPVec2.X and TopRightCornerPos.X >= WTSPVec2.X and TopLeftCornerPos.Y <= WTSPVec2.Y and BottomLeftCornerPos.X <= WTSPVec2.X and BottomRightCornerPos.X >= WTSPVec2.X and BottomLeftCornerPos.Y >= WTSPVec2.Y then
				--Simple check
				table.insert(Visible, v.Name)
			end
		end
	end
	print(table.unpack(Visible))
	Visible = {}
end)

I wasted so much time doing this script and it only print if the center of the part is in the Frame.

1 Like

I updated the script because the corner calculation was bad