Skip to content

Top Layer Provider

A class that allows you to easily create layers on top of UI, for elements like modals, context menus, etc.

Properties

layer.contents

A table that keeps track of all the children of the layer.

Type

luau

Code block has not loaded. An error may have occurred.

layer.contentFrame

The frame that contains both the initial frame and the layer frame.

Type

luau

Code block has not loaded. An error may have occurred.

layer.referenceLayer

The GuiObject that is initially passed. It is called the reference layer because it's data is used as reference position and size for the layer.

Type

luau

Code block has not loaded. An error may have occurred.

layer.state

A table that keeps track of certain useful values related to the layer.

Type

luau

Code block has not loaded. An error may have occurred.

Functions

new

luau

Code block has not loaded. An error may have occurred.

This function is used to create a new top layer. Given a frame, it will nest the frame inside of a new layer frame so that it can be layered properly. This frame is returned, and should be used instead of the original frame.

Something to note is that the layer created attempts to keep the same size as the reference layer, by monitoring the AbsoluteSize of the reference layer. However, using a frame that uses Scale instead of Offset sizing will result in it shrinking to 0, 0. To combat this, place the layer as high as possible in your UI hierarchy (so don't wrap a single frame in a layer, but rather wrap the entire UI in a single layer). You want to use as few layers as possible, only using them to isolate certain interaction areas in your UI.

getLayer

luau

Code block has not loaded. An error may have occurred.

If the passed value is a valid layer or a child of a valid layer, this function will return the layer. Otherwise, it will return nil.

add

luau

Code block has not loaded. An error may have occurred.

This function adds an element to the layer. If it is already parented to the layer, the children are not updated.

remove

luau

Code block has not loaded. An error may have occurred.

This function attempts to find the element in the layer and removes it. If it is not found, nothing happens.

destroy

luau

Code block has not loaded. An error may have occurred.

This function destroys the layer. All children are kept intact if only this function is called, but will be parented to nil. Keep this is mind when developing components as it can lead to memory leaks if these instances are never destroyed. OnDestroy is very useful for this.