I have a folder with bonuses for the player and I use a function with :GetAttribute and :SetAttribute to adjust the bonus values. This is the code:
for bonus, value in pairs(plrdata.Bonuses:GetAttributes()) do -- remove old support plushie bonuses
local plushiebonus = plushie:GetAttribute(bonus)
if plushiebonus then
plrdata.Bonuses:SetAttribute(bonus, value / plushiebonus)
When I call the function in a loop, sometimes this part of the function doesn’t and I can’t figure out why.
For example, when a plushie is equipped the plushies bonus will be multiplied into the current bonus, and divided out when the plushie is unequipped. Unequipping multiple plushies will sometimes cause one of the plushie’s bonuses to not be divided out and the rest of the code in the function runs properly. I think that this has to be the issue because its the only part of my code acting strange and everything else works 100% of the time, whereas sometimes this part will not run.
When I said they’re all numbers I meant all of the values I’m changing are numbers, bonus is a string and all of the attributes do exist.
My issue is that when I run this code in a loop, this code does not always set the attribute. There are no errors and it does work, just not 100% of the time and I can’t figure out why because its not my code