Help with making a healthbar for a tool

Hello fellow developers ! I have prepared a shield for my game but the problem is that the shield deflects all the attacks it is receiving from any direction so the player can just keep the shield equipped for the whole game so I have decided to make a health bar for my shield after which the shield will be destroyed from the players backpack but I don’t know how to do this and would really appreciate any help I receive.

Make a value which would be the health so for example : Health = 100
The health bar can be sized using Current Health / Max Health which will be from 1 to 0 (in scale). (Example: Health is 90 and Max Health is 100. 90 / 100 = 0.9)
Can’t really script a whole system for you tho.

1 Like

Can I just make a health value for my shield and make it equal to the humanoid health will it work?

No since you want the player not be be damaged while they have a shield on.
Make a numberValue or IntValue object and use that. Make sure it’s all server side so no funny business goes on.

1 Like

I did some brainstorming and I have done this so far

local shield = script.Parent
game.ServerStorage.Shield.NumberValue.Value = 100
local shieldhealth = game.ServerStorage.Shield.NumberValue.Value

now I am thinking that I should make that every hit from a weapon will do the damage assigned to the weapon to the shield and every time the number value will be number value - damage taken and once the value goes to 0 , I will write as if shieldhealth = 0 then destroy shield.clone()
will this work ? I made it client side as well :grinning:

Hey!

You can easily add a IntValue | Roblox Creator Documentation to the shield tool first of all. You can set this value to any specific value you want (100 is the default Humanoid | Roblox Creator Documentation health).

Now, as it seems you have a detecting system for the shield blocking any damage, change this script and remove some health of the shield anytime it gets hit.

Also add a if function to it and check if the clamp value of math | Roblox Creator Documentation is 0, for example by doing

if math.clamp(CurrentHealth, 0, MaxHealth) == 0 then
    -- Delete the shield tool here
end)

All you need to do in the if function is deleting the tool from the player.

I hope this could help you out with your problem!

Cheers

1 Like

Like this it will make every shield share the same health. You can have a value inside the shield itself so you don’t have to clone it for every player if you do it with server storage.

1 Like

This is what I have made and I have used a number value inside the shield.

if hp < lasthp then
						charhum.Health = lasthp
						shieldhealth = shieldhealth - (lasthp - hp)
						rootpart.Velocity = Vector3.new()

I have defined the shield health as

game.ServerStorage.Shield.NumberValue.Value = 100
local shieldhealth = game.ServerStorage.Shield.NumberValue.Value

Hey!

Please make each shield have it’s individual health. Otherwise it could lead to many issues since each shield would have one health together.

Create a NumberValue as wished in the tool and use that one instead of one in ServerStorage | Roblox Creator Documentation.

Cheers

1 Like

I don’t know why but the code was not working and the functioning of the shield also got disabled , there were no errors but still it kept bugging so I have come to the conclusion of removing the shield. Thnx to all who helped me.