You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
I want to make an armor system where the armor has a hp of 250 and will negate 30% of all damage the player takes. If the armor’s health is 0, then the negation of 30% goes away and the player will take full damage.
What is the issue?
Every time I play the game, the armor hp goes all the way down to 0 immediately. Also, before I tested the armor hp, the negation also doesn’t work.
This proves the armor does take damage, but I don’t know what from.
What solutions have you tried so far?
I’ve tried to make basically the same topic, but my code wasn’t updated to what I have now.
(I’m a little slow when it comes to learning, just a heads up)
Local Script in StarterCharacterScripts
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local health = humanoid.Health
local dmgHolder = 0
local debounce = false
local armor = workspace.ArmorEquip.Value --Duplicate script with bool value and increase negate by 0.1 everytime a class goes up
local negate = 0.3
local function reduceDamage(Damage)
if debounce then
debounce = false
return
end
if armor == true then
debounce = true
dmgHolder = (Damage-(Damage*negate))
health -= dmgHolder
end
end
humanoid.HealthChanged:Connect(function(Damage)
reduceDamage(Damage)
end)
Local Script in StarterGui
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local health = Humanoid.Health
local damageHolder = 0
local equipped = workspace.ArmorEquip.Value
local armorHP = script.Parent.armorHP
armorHP:SetAttribute("Health", 250)
local function detectDamage(humanoid, Damage)
if equipped == true then
script.Parent.Parent.Visible = true
local atriArmor = armorHP:GetAttribute("Health")
atriArmor-=Damage --Decreases HP of Armor
damageHolder = Damage --Holds in Damage from takeDamage
print("Oh no the Armor Took DAMAGE!!!1!11!")
script.Parent.Size = UDim2.new(Damage / atriArmor, 0, 1, 0)
else
print("THE HUMAN IS TAKING DAMAGE")
equipped = false
script.Parent.Parent.Visible = false
humanoid:TakeDamage(Damage)
end
end
detectDamage(Humanoid, damageHolder
Oh, thanks for the debugging reminder. I keep forgetting I should print variables, anyways I set the health as 250 in the attribute, and the attribute it an IntValue. Then I got 250
Oh so the problem with that is, I have scripts all over the workspace that do damage. Most of them have the Humanoid:TakeDamage(num) The others have hum.Health = 0 If they get touched by a humanoid.
Yes, All the player is touching at the start is a part and a handgun I made. I’ll try to disable all the scripts as well. But as far as I know the ones that do Humanoid:TakeDamage(num) only activates when they are touching the player
Theres a Gui I made for showing the health, that goes all the way down and disappears when I play the game. However, the atriArmor had a health of 250 still, which is full health. I’m sorry I didn’t clarify enough. This was also before I did the print debug for atriArmor
I’m sorry for the long wait as well, I was really busy yesterday.
But the day before yesterday, I changed my code a bit and a friend helped me with this. So whenever I put in a number for the damage holder, the armor will take damage. But when I get hit by an enemy, the armor doesn’t take damage.
Here’s the script. It’s also a local script in StarterGui as well.
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local health = Humanoid.Health
local damageHolder = 0
local equipped = workspace.ArmorEquip.Value
local armorHP = script.Parent.armorHP
armorHP:SetAttribute("Health", 250)
armorHP:SetAttribute("MaxHealth", 250)
local function detectDamage(humanoid, Damage)
if equipped == true then
script.Parent.Parent.Visible = true
local atriArmor = armorHP:GetAttribute("Health")
local MaxatriArmor = armorHP:GetAttribute("MaxHealth")
local healthBar = atriArmor/MaxatriArmor
print(armorHP:GetAttribute("Health"))
armorHP:SetAttribute("Health",atriArmor - Damage) --Decreases HP of Armor
print(armorHP:GetAttribute("Health"))
damageHolder = Damage --Holds in Damage from takeDamage
print("Oh no the Armor Took DAMAGE!!!1!11!")
script.Parent.Size = UDim2.new(healthBar, 0, 1, 0)
else
print("THE HUMAN IS TAKING DAMAGE")
equipped = false
script.Parent.Parent.Visible = false
humanoid:TakeDamage(Damage)
end
end
detectDamage(Humanoid, damageHolder)
It also seems like you did it right. But just to make sure, check the size of the GUI health in the properties when you run the game to see what progress has been done. I also suggest debugging the damage amount. (Print it).
I moved the lines to where you’ve told me to, and it says there is an unknown global ‘atriArmor’
if equipped == true then
script.Parent.Parent.Visible = true
print(armorHP:GetAttribute("Health"))
armorHP:SetAttribute("Health",atriArmor - Damage) --Decreases HP of Armor
local atriArmor = armorHP:GetAttribute("Health")
local MaxatriArmor = armorHP:GetAttribute("MaxHealth")
local healthBar = atriArmor/MaxatriArmor
print(armorHP:GetAttribute("Health"))
damageHolder = Damage --Holds in Damage from takeDamage
print("Oh no the Armor Took DAMAGE!!!1!11!")
script.Parent.Size = UDim2.new(healthBar, 0, 1, 0)
else
print("THE HUMAN IS TAKING DAMAGE")
equipped = false
script.Parent.Parent.Visible = false
humanoid:TakeDamage(Damage)
end
end
It also printed out the damage and it goes from 250 to 225, if I put 25 in damage holder and it says the armor took damage.
function attack(target)
if (myRoot.Position - target.Position).magnitude < 5 then
grabAnim:Play()
grabSound:Play()
if target.Parent ~= nil then
if playerArmor.Value == true then
target.Parent.Humanoid:TakeDamage(10)
else
target.Parent.Humanoid:TakeDamage(25)
end
end
wait(1)
end
end