How do I check if a GUI is on screen?

I’m trying to check if a gui is on screen or not,
I have had one idea though:
Check and see if all of the corners are on screen,
but I cannot figure out how to do this.

I just need any solution that will tell me if it’s on screen.

Example:



Edit:

alright, so it seems as none of the solutions i’ve been given actually work…
so i basically just went with my original solution
which is to just get the corners and check if they are on screen,
which does not count for gui rotation,
which is why this topic is technically not finished, and why this post is not marked as solution

if anyone is interested, i was using it for my is object on screen function for RNMU,
which basically makes a 2d bounding box around the part (also a function i added),
then checks if the 2d bounding box is on screen
(which is the best solution that exists currently, though if anyone has a better solution, post it here)

Try this:

local function IsOnScreen(GuiObject)
if (GuiObject.Position.Y.Scale >= 0 and GuiObject.Position.Y.Scale < 1 and GuiObject.Position.X.Scale >= 0 and GuiObject.Position.X.Scale < 1) then
	return true
else
	return false
	end
end
1 Like

i dont know if im using this wrong, but it is giving me “true” every single time ?

There are 2 ways of detecting this depending on if your frame’s position is using Scale or Offset (Don’t use them both at the same time cause it will always print “It’s on screen”):

local Camera = workspace.CurrentCamera
local Frame = script.Parent

-- Scale --

if Frame.Position.X.Scale < 1 and Frame.Position.Y.Scale < 1 then
	print("It's on screen")
else
	print("Not on screen")
end

-- Offset --

if Frame.Position.X.Offset < Camera.ViewportSize.X and Frame.Position.Y.Offset < Camera.ViewportSize.Y then
	print("It's on screen")
else
	print("Not on screen")
end

image

1 Like

is there a way i can detect scale/offset without doing an if statement for every value ?

Not sure what you mean, but depending if your frame’s position uses Scale or Offset you will need a different if statement. If you don’t want to create an if statement for every value just use an in pairs loop.

1 Like

i want to detect if it’s using scale or offset

Maybe try:

local Camera = workspace.CurrentCamera
local Frame = script.Parent

if Frame.Position.X.Offset == 0 and Frame.Position.Y.Offset == 0 and Frame.Position.X.Scale >= .1 and Frame.Position.Y.Scale >= .1 then
	print("Using Scale")
	
elseif Frame.Position.X.Offset >= 1 and Frame.Position.Y.Offset >= 1 and Frame.Position.X.Scale == 0 and Frame.Position.Y.Scale == 0 then
	print("Using Offset")
else
	print("Using Offset and Scale")
end
1 Like

uh i guess

while true do
if game.players.localplayer.playergui.true.visible = true then
print("yes")
end
end
1 Like

Maybe this:

local ScreenGui = script.Parent.Parent
local Frame = ScreenGui.Frame
Frame:GetPropertyChangedSignal("Visible"):Connect(function()
if Frame.Visible == true then
print("Gui is on screen")
end
end)

You can change a bit. I’m not sure where you putted GUI.

1 Like

Try this:

local obj = script.Parent.Frame
local ViewSize = workspace.Camera.ViewportSize -- ScreenSize
local abs_size, abs_pos = obj.AbsoluteSize, obj.AbsolutePosition
		
local x1,x2,y1,y2 = abs_pos.X > ViewSize.X,abs_pos.X+abs_size.X < 0,abs_pos.Y+abs_size.Y*.5 > ViewSize.Y,abs_pos.Y+abs_size.Y < 0

if x1 or x2 or y1 or y2 then
	return false -- object isn't on screen
else
	return true -- object is on screen
end
1 Like

red means it’s not on screen, this isnt a perfect solution

U forgot to add a wait() so that would exhaust the script

1 Like

those “solutions” won’t work anyways, because that is not at all what i meant

Where would it be if its not on the screen? Couldn’t you just check if its enabled true or false?

outside of the boundaries where you cant see it

Okay, i’m just really confused by the use case here. I assume that if its off the screen you (your script) has put it there so why would you need to detect it.

because moving a gui doesnt tell me if it’s out of boundaries or not ???

Right but you’re moving it, you know how big the screen is, why would you not know if its off the screen or not. I don’t get it.

Are you trying to move the gui with an endless loop and test its position somewhere and stop the loop?

I know what you’re asking for. Give me a few and I’ll write you something.