Skip to content

Space ​

A Space is the renderer root — a widget wrapper around a Roblox LayerCollector (ScreenGui, BillboardGui, or SurfaceGui). Every widget tree is mounted into a Space, and the Space is what actually puts the tree on screen.

luau
const Space = PeanutUI.Space

Roblox reference: ​

Creating a Space ​

Each Space type has a create* constructor and a matching get* lookup. Spaces are registered by name, so creating two with the same name errors.

Space.createScreenSpace(name, props?) ​

Creates a ScreenGui-backed Space, parented to the local player's PlayerGui.

luau
const screen = Space.createScreenSpace("Main", {
    displayOrder = 1,
    ignoreGuiInset = true,
})

Space.createBillboardSpace(name, props?) ​

Creates a BillboardGui-backed Space.

luau
const billboard = Space.createBillboardSpace("HealthBar", {
    adornee = somePart,
    size = PeanutUI.Size(200, 50),
})

Space.createSurfaceSpace(name, props?) ​

Creates a SurfaceGui-backed Space.

luau
const surface = Space.createSurfaceSpace("Sign", {
    adornee = somePart,
    face = Enum.NormalId.Front,
})

Lookup ​

FunctionDescription
Space.getScreenSpace(name)Returns a registered ScreenSpace.
Space.getBillboardSpace(name)Returns a registered BillboardSpace.
Space.getSurfaceSpace(name)Returns a registered SurfaceSpace.

Shared properties ​

All Space types share these properties:

PropertyTypeDescription
namestringSpace name (defaults to the registry key).
visiblebooleanWhether the Space is enabled.
zIndexBehaviorEnum.ZIndexBehaviorZ-index behavior.
absoluteSizeVector2Absolute size (read-only).
absolutePositionVector2Absolute position (read-only).
absoluteRotationnumberAbsolute rotation (read-only).
screenSizestringActual size on screen (read-only).
screenPositionstringActual position on screen (read-only).

ScreenSpace properties ​

In addition to the shared properties:

PropertyTypeDescription
displayOrdernumberDraw order between ScreenGuis.
clipToDeviceSafeAreabooleanClip to the device safe area.
ignoreGuiInsetbooleanIgnore the topbar inset.
safeAreaCompatibilityEnum.SafeAreaCompatibilitySafe area compatibility mode.
screenInsetsEnum.ScreenInsetsWhich insets to apply.

BillboardSpace properties ​

In addition to the shared properties:

PropertyTypeDescription
activebooleanWhether the billboard receives input.
adorneeInstance?Instance the billboard is attached to.
alwaysOnTopbooleanRender on top of everything.
brightnessnumberBrightness.
clipsDescendantsbooleanClip children to bounds.
currentDistancenumberCurrent distance to camera (read-only).
distanceStepnumberDistance step for updates.
extentsOffsetVector3Extents offset.
extentsOffsetWorldSpaceVector3World-space extents offset.
lightInfluencenumberHow much lighting affects the billboard.
maxDistancenumberMax render distance.
playerToHideFromInstance?Player who should not see it.
sizeSizeBillboard size.
sizeOffsetVector2Size offset.
studsOffsetVector3Studs offset.
studsOffsetWorldSpaceVector3World-space studs offset.

SurfaceSpace properties ​

In addition to the shared properties:

PropertyTypeDescription
activebooleanWhether the surface receives input.
adorneeInstance?Instance the surface is attached to.
faceEnum.NormalIdFace of the part to render on.
alwaysOnTopbooleanRender on top of everything.
brightnessnumberBrightness.
canvasSizeVector2Canvas size.
clipsDescendantsbooleanClip children to bounds.
lightInfluencenumberHow much lighting affects the surface.
maxDistancenumberMax render distance.
pixelsPerStudnumberPixels per stud.
sizingModeEnum.SurfaceGuiSizingModeSizing mode.
toolPunchThroughDistancenumberTool punch-through distance.
zOffsetnumberZ offset.

Scaling ​

A Space owns the scale function used to convert pixel values into the Space's scale. Widgets read it through getSpace(), and it can be changed at runtime:

luau
screen.changeScaleFn(function(px, getOriginal)
    return px * 2
end)

Changing the scale fires the ScaleChanged signal, which widgets listen to in order to redraw scaled properties.

See Scaling for auto scaling.

Events ​

EventSignature
ChildAdded(child: BaseInterface) -> ...boolean?
ChildRemoved(child: BaseInterface) -> ...boolean?
PropertyChanged(key: string, value: any) -> ...boolean?
ObjectDestroying(object: LayerCollector) -> ...boolean?
Destroying() -> ...boolean?
Destroyed() -> ...boolean?

INFO

ObjectCreated is not available on Spaces — they use custom object creation. ObjectDestroying is still available because it is part of Widget.destroy.

Children ​

Spaces support the same child API as widgets:

MethodDescription
addChild(child)Adds a child widget.
removeChild(child, andDestroy?)Removes a child, optionally destroying it.
clearChildren()Removes all children.
childrenThe current child list.