So currently if you try to perform arithmetic on attributes like this:
local part = Instance.new("Part")
part.Parent = workspace
part:SetAttribute("test",1) -- create an attribute called 'test' and give it a value of '1'
part:GetAttribute("test") += 1 -- that will cause an error
It will cause an error because you can’t perform arithmetic on attributes like that so I was confused about this because I didn’t know how to perform arithmetic on attributes and in the end I found a solution but I don’t know if it’s the most efficient one:
local part = Instance.new("Part")
part.Parent = workspace
part:SetAttribute("test",1) -- create an attribute called 'test' and give it a value of '1'
print(part:GetAttribute("test")) -- prints '1'
local test = part:GetAttribute("test") -- store the 'test' attribute value as a variable so we can perform arithmetic on it later
test += 1
part:SetAttribute("test",test)
print(part:GetAttribute("test")) -- prints '2'
That code above is currently my best solution to the problem but I would like to know if it’s the most efficient one or if this could be done in a more efficient way?