Is there a more efficient way of incrementing Attributes?

Hello! Ever since Attributes released, I have been converting all my games to Attributes rather than BaseValue.

However, when I used BaseValues, I did

NumberValue.Value += 1

rather than

NumberValue.Value = NumberValue.Value + 1

However

When I use attributes, it gets even more crazy…

NumberValue:SetAttribute("Value", NumberValue:GetAttribute("Value") + 1)

That is really the only thing I really miss about BaseValues. If you know of a better way of incrementing Attributes, please let me know. Thanks!

2 Likes

The only thing I can think of is making a function to simplify it.

local function incrementAttribute(instance, attribute)
--//Increments an attribute on an instance by +1
instance:SetAttribute(attribute, instance:GetAttribute(attribute) + 1)
end

incrementAttribute(myPart, "Value")
4 Likes

Why didn’t I think of this! I will be sharing this with all my friends.
Decided to modify it a little bit so you can have a different Incremented value (Since I use those a lot)

local function IncrementAttribute(InstanceLocation, AttributeName, Incremented)
    InstanceLocation:SetAttribute(AttributeName, InstanceLocation:GetAttribute(AttributeName) + Incremented)
end
3 Likes