Skip to content

Value

Import Weave.Value from the Weave module.

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

A Weave Value is an object that stores any value.

local health = Value.new(100)

health:get() --> 100

health:set(99)

Usage

Use :get() to read the value

local health = Value.new(100)

health:get() --> 100

Use :set() to change it

health:set(25)

health:get() --> 25

Value can store any Luau type:

local name = Value.new("Bob")

local ammoAmount = Value.new(50)

local sprinting = Value.new(false)

local inventory = Value.new({ "apple", "pear" })

local basePlate = Value.new(workspace.Baseplate)

.Changed

When a Value changes, .Changed is fired.

local health = Value.new(100)

health.Changed:Connect(onHealthUpdated)

See the updated value:

health.Changed:Connect(function(newHealth: number)
    print("The new health is: ", newHealth)
end)

:Disconnect() when you're done listening to changes

local connection = health.Changed:Connect(function(newHealth: number)
    print("The new health is: ", newHealth)
end)

-- do some stuff

connection:Disconnect()