How do I do math with attributes

instead of having to do this everytime :skull:

player:WaitForChild("PlayerData"):SetAttribute("AttributePoints",(player:WaitForChild("PlayerData"):GetAttribute("AttributePoints") + 1)

is there a way that I can add it like I would add normal numbers in other scripts?
an example being

level += 1

You could probably simplify it by defining a function instead, otherwise I don’t think there’s any syntax sugary way of doing it.

local function incrementAttr(name, increment)
    local oldValue = player.PlayerData:GetAttribute(name)
    local newValue = oldValue + increment

    player.PlayerData:SetAttribute(name, newValue)
end

You could make this modular so you can use it in numerous places without copy-pasting.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.