So I have a skill tree for my game and you can put points on stats like Bonus Damage, Critical hits etc… and these values gets calculated for instance whenever a player attacks > check if Bonus Damage has point, if so > buff attack damage etc… and I was wondering what is the best/efficient method to calculate the outcome of attacks? I thought of just checking for every skill if it has a point then > add to outcome but that could look messy and be inefficient. I wanna know if there’s a more efficient way to do this
I would probably keep some sort of IntValue in ServerStorage that has their current aggregate statistics and just increment them when you unlock a skill. Otherwise, keep track of the skills via some sort of table dictionary structure. Loops through the table (which is literally a skill tree of sorts) and if some boolean value is true under an entry, check for it’s “stats boosts” and increment the bonus damage / critical hit values the user has when they attack.
local SkillTree = {
["Skill1"] = {
["active"] = true,
["stat_boosts"] = {
CriticalDamage = 40,
BonusDamage = 10
}
["Skill2"] = {
["active"] = false,
["stat_boosts"] = {
CriticalDamage = 50,
BonusDamage = 15
}
}
GetSkillBonuses.OnServerEvent:Connect(GatherBoosts)
function GatherBoosts(player)
local stat_bonuses_to_return = {}
for i, v in pairs(SkillTree) do
if v["active"] == true then
table.insert(stat_bonuses_to_return, v["stat_boosts"])
end
end
GetSkillBonuses:FireClient(player, stat_bonuses_to_return)
end)
You likely want to keep this data on the server-side and have a SkillTree object instantiated for every player when they join. You’ll probably have to end up using RemoteEvents/RemoteFunctions as well as DataStoreService if you want this to work safely and save across play sessions.
What I gave you is only an idea though. There are lots of ways to do this that don’t involve tables and maybe just have ServerStorage instance values.
It’d be a lot easier to help if you provided some examples of what you’ve already got or what your first idea is if you haven’t tried implementing anything yet.