How do I tell if a GUI is off the screen

You’re going to be best off using the AbsolutePosition and AbsoluteSize properties of your guis. Using either scale or offset will ignore any properties of the other when doing the calculations.

Since you said you used scale you could update this to use scale instead, but doing it this way will make it work if you ever add any offsets.

Additionally Roblox’s top bar can mess with the numbers, so you will want to do something like this.

local guiInset = game:GetService("GuiService"):GetGuiInset()
local function isInScreen()
	local pos = script.Parent.AbsolutePosition + guiInset
	return pos.X + script.Parent.AbsoluteSize.X <= game.Workspace.CurrentCamera.ViewportSize.X and pos.X >= 0
		and pos.Y + script.Parent.AbsoluteSize.Y <= game.Workspace.CurrentCamera.ViewportSize.Y and pos.Y >= 0
end

You might find it easier to detect if it’s in a parent frame however. So something like this

local function isInParent(guiObject)
	return guiObject.AbsolutePosition.X >= guiObject.Parent.AbsolutePosition.X and guiObject.AbsolutePosition.X + guiObject.AbsoluteSize.X <= guiObject.Parent.AbsolutePosition.X + guiObject.Parent.AbsoluteSize.X 
		and guiObject.AbsolutePosition.Y >= guiObject.Parent.AbsolutePosition.Y and guiObject.AbsolutePosition.Y + guiObject.AbsoluteSize.Y <= guiObject.Parent.AbsolutePosition.Y + guiObject.Parent.AbsoluteSize.Y
end
4 Likes