Is there anyway to check if a frame is completely viewable for player?

I wanted to know if theres a way to check if a frame is completely in the view of player, for example, i have a frame and the half of the frame is outside of the player’s view, i want to check if the entire frame is in the view of player. I want this for a notification system, i know i can check AbsoluteContentSize.Y but this is not what i want , from where the resolution is different on each device. I want to make it like if the frame is not in the view then It’ll not let the script that is about duration and stuff run until it comes to view, so is there anyway to check if the frame is completely in view?.

1 Like

You could create a chain of checks to determine if a frame is visible.
I would advise against using this, and more-so just tracking variables so it’s more efficient on performance.

local function IsWithinBounds(Frame: GuiObject, Parent: GuiObject): boolean
    local absPos = Frame.AbsolutePosition
    local absSize = Frame.AbsoluteSize
    local parentAbsPos = Parent.AbsolutePosition
    local parentAbsSize = Parent.AbsoluteSize

    return (
        absPos.X + absSize.X < parentAbsPos.X or -- Too far left
        absPos.X > parentAbsPos.X + parentAbsSize.X or -- Too far right
        absPos.Y + absSize.Y < parentAbsPos.Y or -- Too far up
        absPos.Y > parentAbsPos.Y + parentAbsSize.Y -- Too far down
    )
end

local function IsVisible(Frame: GuiObject): boolean
    local visible = true
    local currentFrame = Frame

    while currentFrame do
        if currentFrame:IsA("GuiObject") then
            -- Check if the current frame is visible
            if not currentFrame.Visible then
                visible = false
                break
            end

            -- Check if it is within bounds of parent (if parent is GuiObject)
            local parent = currentFrame.Parent
            if currentFrame:IsA("GuiObject") and (parent and parent:IsA("GuiObject")) and parent.ClipsDescendants then
                if IsWithinBounds(currentFrame, parent) then
                    visible = false
                    break
                end
            end

        elseif currentFrame:IsA("ScreenGui") then
            -- Check if the ScreenGui is enabled
            if not currentFrame.Enabled then
                visible = false
                break
            end
        end

        -- Traverse up to the parent
        currentFrame = currentFrame.Parent
    end

    return visible
end

I wrote this on a whim, I’m not certain if this works.

Well, i tested the IsWithinBounds function, and it returned false when the frame was in a view and when it was not in the view.hmm

Oh, whoops! In the “IsWithinBounds” function, I accidentally included a “not” within the return value. You can remove that, and it should behave as intended.

Hmm , still, it returned false when thr frame was in view and wasn’t in view so i think if i remove the not it returns true when the frame is in view and not i guess. Still is a problem

I have an idea which i do not know if it works. I can get the AbsoluteSize.Y of the screen by using a full screen frame ig , for example it is 700, then i can do something like

local Size=700
local result=frame.AbsoluteSize.Y+frame.AbsolutePosition.Y
if result>=Size then return false elseif result<Size then return true end

Will it work?

Nevermind, didn’t work. Help , the max Size is 1080 and the result is 1022 and is already outside of the screen

–i managed to do something like this, i don’t like this way but this is the only working way i know for my job, if you know a different way tell me

local function IsInsideHolder(MainHolder:GuiObject)
-- my Holder has a UIPadding,  UIListLayout, and the templates 
local result=MainHolder:FindFirstChildOfClass'UIPadding'.PaddingTop.Offset+game:GetService'GuiService':GetGuiInset().Y+MainHolder:FindFirstChildOfClass'UIListLayout'.AbsoluteContentSize.Y
if result<=MainHolder.AbsoluteSize.Y then return true
elseif result>MainHolder.AbsoluteSize.Y then return false
end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.