What is the best way of making "Buffs"?

Hey there, good people of the ROBLOX Devforum! I am making an Open World ATLA game, and I am in dire need of some help. I want to make different buffs from moves and armor / accessories. For example, “Wind Speed” would make you faster and jump higher, also reducing fall damage. Some accessories might give you more
Screenshot 2024-03-23 070615
health and less knockback. How do I make it? I want to make it like project slayers. Displaying it is not a problem either, I know how to do that.

I believe it truly depends on how you structure your character in scripts and how their stats function.
While I can’t give you an exact bit of code, I can explain how I made it for my project:

My players are made with a custom metatable object, in which I have a stat table that contains every stat that matters in the game using the format of

-- Snippet of player script
StatTable = {
    Attack = {Base = 10, Bonus = 0, Total = 0}
}

And within the same object I made a function to calculate stats, where it runs through every buff and gives it the player’s StatTable to do calculations depending on what the buff is supposed to do, so I’d have a Buff object that does

-- Example function, unique to every buff
function calculate(StatTable)
    StatTable.Attack.Bonus += 5
    return StatTable
end

And then the original function within the Player object would just do

-- Iterating through every stat with a for loop
StatTable.Attack.Total = StatTable.Attack.Base + StatTable.Attack.Bonus

Now you can make scripts that read the stats total, and implement behavior with it.
You could simplify this further by reducing the buff to be a string that explains what it does to the stat, and then just parsing the string with a custom function, but it all depends on how you want to implement it.

This is probably far from the best way, but it would be difficult to outline the best considering that it should mesh together with whatever player system you have.

So in general, you can make it so players have a base stat, then have buffs that can add to a bonus stat, which you can then combine into a total (readable) stat that you can use to modify your game’s logic.

1 Like

This works great! The only thing I need is how to adjust the bonus when they equip weapons, armor, etc. I am pretty sure I just detect when the armor is removed, and I have the stat buffs listed for it.

You could structure the armor to function similar to your buffs, or you could attach buffs to armor, and then remove the buffs whenever the armor is removed.