What do you want to achieve? Keep it simple and clear!
This script is under StarterGui and whenever the player gets hit, the armor takes the damage. Then once the armor’s hp goes to 0 the armor is unequipped.
What is the issue?
Whenever I run the script I get this error, attempt to perform arithmetic (sub) on nil and number
I also need help actually dividing the damage the player takes by 30%, but that can be figured out later.
When I run the game this happens
What solutions have you tried so far?
I’ve tried searching online, but I can’t find a solution relating to my problems
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 = 250
local function detectDamage(humanoid, Damage)
local AtriArmor = humanoid:GetAttribute("armorHP")
if equipped == true then
script.Parent.Parent.Visible = true
AtriArmor-=Damage --The line where the error is
damageHolder = Damage
print("Oh no the Armor Took DAMAGE!!!1!11!")
script.Parent.Size = UDim2.new(AtriArmor / Damage, 0, 1, 0)
else
print("THE HUMAN IS TAKING DAMAGE")
AtriArmor = 0
script.Parent.Parent.Visible = false
equipped = false
humanoid:TakeDamage(Damage)
end
end
detectDamage(Humanoid, damageHolder)
I assume that you want the armor to only take damage when it’s hit, in that case, I recommend opening a new topic since that would be a little more complex