Skip to main content

New

Constructs a Roblox instance, hydrates an existing one, or builds a Seam component.

TypeSinceScoped
Declaration0.0.1Yes

Constructor​

New(
Class : string | Instance | Component,
Properties : {[any] : any},
Scope : Scope? -- Passed automatically by Scope:New
) -> Instance | any

Usage​

New is Seam's instance constructor. It can create instances, hydrate existing ones, or invoke components.

Create or hydrate​

local Frame = New("Frame", {
Size = UDim2.fromScale(0.5, 0.5),
})

local Existing = Gui:FindFirstChild("Frame")

New(Existing, {
Size = UDim2.fromScale(0.5, 0.5),
})

Property table rules​

Key / value shapeBehavior
String key + plain valueAssigns instance[key] = value
String key + Seam stateBinds the state to that property (Value, Computed, Spring, etc.)
Table key with __SEAM_INDEXRuns a declaration such as Children, Attribute, OnEvent, StyleSheet, Lifetime
Numeric keyTreated as an implicit child (Children)
New("TextButton", {
-- Plain assignment
Text = "Click",

-- State binding
BackgroundColor3 = Spring(HoverColor, 25, 1),

-- Declaration
[Attribute "Id"] = "Primary",
[OnEvent "Activated"] = function()
print("clicked")
end,

-- Implicit child
New("UICorner", {
CornerRadius = UDim.new(0, 8),
}),
})

Components​

If the first argument is a component (from Component(...)), New calls it with the optional scope and the properties table:

local Button = require(Path.To.ButtonComponent)

New(Button, {
Text = "Save",
})

When created through Scope:New, that scope is passed into the component's Init / Construct methods.

Scoped usage​

local MyScope = Scope(Seam)

local Gui = MyScope:New("ScreenGui", {
Parent = PlayerGui,
})

Anything returned from Scope:New is registered on the scope for cleanup.