diff --git a/src/attributeutils/src/Shared/AttributeValue.lua b/src/attributeutils/src/Shared/AttributeValue.lua index a228aff16c2..225dd92285c 100644 --- a/src/attributeutils/src/Shared/AttributeValue.lua +++ b/src/attributeutils/src/Shared/AttributeValue.lua @@ -89,6 +89,22 @@ function AttributeValue.Observe(self: AttributeValue): Observable.Observab return RxAttributeUtils.observeAttribute(self._object, self._attributeName, rawget(self :: any, "_defaultValue")) end +--[=[ + Allows you to set a value, and returns a clean up that resets to default value + + @param value T + @return () -> () -- Cleanup +]=] +function AttributeValue.SetValue(self: AttributeValue, value: T) + self._object:SetAttribute(rawget(self :: any, "_attributeName"), value) + + return function() + if self.Value == value then + self._object:SetAttribute(rawget(self :: any, "_attributeName"), rawget(self :: any, "_defaultValue")) + end + end +end + --[=[ The current property of the Attribute. Can be assigned to to write the attribute. @@ -124,7 +140,7 @@ end function AttributeValue.__newindex(self: AttributeValue, index, value) if index == "Value" then - self._object:SetAttribute(rawget(self :: any, "_attributeName"), value) + self:SetValue(value) elseif index == "AttributeName" then error("Cannot set AttributeName") else