very simple issue, that i unfortunately do not know how to fix
this is one table:
when i print its contents, everything is mixed up:
meaning, if i try to get the buff value (which is index 3), it will instead return… nil?
for _, value: IntValue in gameplayValues:GetDescendants() do
if value.Name ~= assignedValue then continue end
local traitBuff: number = traitStats[trait][3] -- 3rd index is always the buff value (number)
warn(traitStats[trait])
warn("Applying " .. trait .. " to " .. value.Name)
if traitStats[trait].isMultiply then
if remove then
value.Value = math.floor(value.Value / traitBuff)
else
value.Value = math.floor(value.Value * traitBuff)
end
else
if remove then
value.Value -= traitBuff
else
value.Value += traitBuff
end
end
end
would it be better to contexualize the bonus and have two keys, bonus and bonusType, instead of one key for a specific bonus that doesn’t exist in all of them?
local buffs = {
Brutal = {
description = "You do not mess around in melee combat.",
buff = "+10% melee damage",
bonus = 1.10,
bonusType = "damage",
isMultiply = true
},
Swift = {
description = "Even under pressure, you remain swift with your reloads.",
buff = "+15% reload speed",
bonus = 1.15,
bonusType = "reloadSpeed",
isMultiply = true
},
... etc
}
then, you can still index .bonus to get how much it would add to the certain statistic, and that statistic is determined by .bonusType, which you can make it check for for things like damage, reloadSpeed, aimSpeed, etc…
if you don’t want to do this you can still always check if they exist like this:
if traitStats[trait].meleeDamageBonus then
...
end
if traitStats[trait].reloadSpeedBonus then
...
end
but in my opinion, the first idea i proposed would be cleaner and more elegant