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 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.
- 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
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)
- 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.