From 6f45fccb2d9df7298503ad3308b9d85481c6917d Mon Sep 17 00:00:00 2001 From: KreatorKols Date: Tue, 30 Sep 2025 21:45:40 -0500 Subject: [PATCH 1/2] feat: Add SetValue method to AttributeValue for assignment with cleanup --- .../src/Shared/AttributeValue.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/attributeutils/src/Shared/AttributeValue.lua b/src/attributeutils/src/Shared/AttributeValue.lua index a228aff16c2..a038395cbed 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 rawget(self :: any, "_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 From da8d1ba3310205c925785895c05ec1f93464b918 Mon Sep 17 00:00:00 2001 From: KreatorKols Date: Tue, 30 Sep 2025 21:49:11 -0500 Subject: [PATCH 2/2] fix: Correct condition in SetValue method to use self.Value for comparison --- src/attributeutils/src/Shared/AttributeValue.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/attributeutils/src/Shared/AttributeValue.lua b/src/attributeutils/src/Shared/AttributeValue.lua index a038395cbed..225dd92285c 100644 --- a/src/attributeutils/src/Shared/AttributeValue.lua +++ b/src/attributeutils/src/Shared/AttributeValue.lua @@ -99,7 +99,7 @@ function AttributeValue.SetValue(self: AttributeValue, value: T) self._object:SetAttribute(rawget(self :: any, "_attributeName"), value) return function() - if rawget(self :: any, "_value") == value then + if self.Value == value then self._object:SetAttribute(rawget(self :: any, "_attributeName"), rawget(self :: any, "_defaultValue")) end end