Need Help on Armor Mitigation System

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?

I want to make an armor system where when the player puts on the armor, they get a second “health bar” (the armor health bar) and if they get hit, the damage is reduced by 30%, then the armor takes the reduced damage, same with the player’s health.

  1. What is the issue?

I’m not entirely sure what functions to use for this problem, I also don’t fully understand what to use to get numbers across scripts.
Hierarchies
image
image

This is the HealthGui script

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local negation = script.Parent.Parent.Parent.Parent.ArmorGui.ArmorBackground.ArmorHPDisplay.leftoverDamge.Value
local armor = workspace.ArmorEquip.Value

humanoid.HealthChanged:Connect(function(Damage)
	if armor == true then
		Damage*=negation
		script.Parent.Size = UDim2.new(Damage / humanoid.MaxHealth, 0, 1, 0)
	else
		script.Parent.Size = UDim2.new(Damage / humanoid.MaxHealth, 0, 1, 0)
	end
end)

This is the ArmorGui script (Remote Event in Replicated Storage called ArmorEvent)

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local damageValue = script.Parent.leftoverDamge.Value
local equipped = workspace.ArmorEquip.Value --Checks if user equipped the armor

local armorEvent = game.ReplicatedStorage.ArmorEvent

--Armor stats
local armorHP = script.Parent.ArmorHp 
local armorNegation = 0.3 

armorHP:Connect(function(Damage)
	if equipped == true then
		script.Parent.Parent.Visible = true
		armorHP -= Damage
		damageValue = Damage*armorNegation
		script.Parent.Size = UDim2.new(Damage / armorHP, 0, 1, 0)
		
	else
		
		armorHP = 0
		armorNegation = 0
		script.Parent.Size = UDim2.new(Damage / armorHP, 0, 1, 0)
	end
end)
  1. What solutions have you tried so far?

I’ve been trying to use Remote Events and Int Values to get the numbers across from one script to the other, but it hasn’t been working. I’ve also looked for tutorials, and posts on here but I can’t come up with a solution.

So, uh… I don’t want to ruin your idea, but can you explain how this will resolve one-shot capabilities?

Rephrased, how would you combat one-tap shotguns using this “armor.”

According to me, there is NO way to revive a dead humanoid. And a shotgun up-close kills someone, well you ain’t gonna get the time to negate 30% of the damage and that person will be dead.

That is very true, but in my game the enemies aren’t going to be wielding anything like that. Plus it’s single player so I don’t really have to worry about it too much

I would just disable the death state, then kill the humanoid manually in the case of 0 HP.

Solution:
.HealthChanged, get the delta, reduce the damage by 30%.

Oh alright then, my bad!

oogaboogarandomtextbruvgrubhublol

So in a previous save, I used .HealthChanged in the armor script instead of .Changed. Then it started to not negate the damage, but also just took the same damage without the negation as the Healthbar until the player died.

I believe health changed in a way could work however I do not recommend it as the issue is that the event occurs after damage has been taken which can cause problems if there is a shotgun mechanic or if the humanoid dies and permanently dies as @OceanTubez mentioned where you cannot mitigate the damage because the event happpend after.

One better solution is to modify the server Humanoid:TakeDamage function with a custom function that takes into account armor health or shield health which serves the purpose of preventing in the event before the damage was applied to health.

I’ve been tinkering with your clever suggestion, but every time I try to do simple math or try to modify it in any way. It either doesn’t take away the Armor’s health, or outputs an error.
This might be a big ask, but could you possibly explain the Humanoid:TakeDamage part in more simpler terms please?