Hello Roblox Devs !
So basically, if you’ve played games, you are familiar with the attack / defense system. For example in Minecraft, with the defense and attack point.
So there is some ways to it, but basically, you can use a math algorithm for it :
local function GetRealDamage(damage: number, defense: number): number
local PRECISION = 1000
local MAX_VALUE = 100
damage = damage * (1 -
math.min(MAX_VALUE, math.max(0, defense - damage / 10)) / MAX_VALUE
)
damage = (math.round(damage * PRECISION)) / PRECISION
return damage
end
So basically, you can send the amount of damage a player will take before using the take damage method. It should look like this :
--> The player will take 30 damage
victimHumanoid:TakeDamage(30)
--> The player will take 30 damage, but the victim has 50 defense points
victimHumanoid:TakeDamage(GetRealDamage(30, 50))
And the output of this will be the true damages the victim will take, in this particular case, it will be 15.9
damages.
Of course, this is not the only algorithm, but this one is particularly efficient !