Skip to content

Attach

Import the Attach module from Weave:

1
2
local Weave = require(ReplicatedStorage.Weave)
local Attach = Weave.Attach

Weave provides an Attach function for updating any Instance.

Attach(ScreenGui.CoinDisplay.TextLabel) {
    BackgroundColor3 = Color3.new(1, 1, 1),
    BackgroundTransparency = 0,
}

Value and Computed properties update automatically

local coins = Value.new(1100000)

local coinDisplay = Computed.new(function()
    return styleNumber(coins:get())
end)

Attach(ScreenGui.CoinDisplay.TextLabel) {
    Text = coinDisplay,
}

coins:set(756000)

-- TextLabel.Text is now "75.6k"
Image title
Source: Pet Simulator 99. Attach updates Instance properties automatically

Usage

To use Attach:

  • Call Attach with the Instance you want to update
Attach(Frame) -- TODO: Add Properties
  • Define a table of properties:
Attach(Frame) {
    Size = UDim2.new(1, 0, 1, 0),
}

Attach works on any Instance type and any Property

local brickColor = Value.new(BrickColor.Red())

Attach(workspace.Part) {
    BrickColor = brickColor
}

local visible = Value.new(true)

Attach(ScreenGui.Frame) {
    Visible = visible
}

local cameraType = Value.new(Enum.CameraType.Scriptable)

Attach(workspace.CurrentCamera) {
    CameraType = cameraType
}

Instance Reuse

Attach returns the Instance back to you:

local textLabel = Attach(ScreenGui.TextLabel) {
    Text = "Loading..."
}

print(textLabel.Text) --> Loading...