As a Roblox developer, it is currently too hard to change an attribute’s value based upon its current value.
I commonly find myself doing this to a similar extent:
local value = workspace:GetAttribute("example");
workspace:SetAttribute("example", not value);
Which is overly lengthy for such a simple action.
My proposition is that we get an ‘UpdateAttribute’ method which acts just like the UpdateAsync method of datastores (taking a function that returns the new value). For example:
Though I could create a wrapper function to this, shouldn’t it just be a native feature?
Once more, I’d like to see a ‘IncrementAttribute’ method which takes an incrementor - this’d make attributes that move in incremental steps much easier to add. For example:
If Roblox is able to address this issue, it would improve my development experience because I wouldn’t have to go through the rigmorale of getting and setting an attributes value, it’d make attributes far easier to utilise.
Was needing this yesterday. The biggest use case for me for increment attribute is for weapons, each weapon will have an ammo attribute, and it would be easier to just do weapon:IncrementAttribute("Ammo", -1).
I personally haven’t needed an update attribute, but I see the use case for it.
Would love IncrementAttribute, but I can see some cases where UpdateAttribute would be nice! This is the cleanest I could get my code.
for Place, PlayerInfo in VoteArray do
local Player = PlayerInfo.Player
local Currencies = Player.Currencies
Currencies:SetAttribute("BrickCoins", Currencies:GetAttribute("BrickCoins") + Rewards[Place])
if Place == 1 then
Player.PlayerData:SetAttribute("MultiplayerWins", Player.PlayerData:GetAttribute("MultiplayerWins") + 1)
end
end
This would be great, honestly the lack of these features is probably keeping a lot of people from using attributes because of how ugly their code pattern looks.
Bumping this again to maybe get more attention to it.
It would be so very useful for adding stuff like Player Stats as such
Player:SetAttribute("Coins", Player:GetAttribute("Coins") + 100)
-- New Version:
Player:IncrementAttribute("Coins", 100)
Another things I’d argue for is to add a value argument within the :GetAttributeChangedSignal(), similar to what is seen in ValueBase.Changed
-- Right now
Thing:GetAttributeChangedSignal("Amount"):Connect(function()
var = Thing:GetAttribute("Amount")
end)
-- After
Thing:GetAttributeChangedSignal("Amount"):Connect(function(val)
var = val
end)