Armor system / Defense from Attack true damage

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

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

--> 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 !


This is quite useful, the type of resource I didn’t know I needed lol.
Thanks! :smiley: