I'm currently trying to make hearts disappear when the player's health reaches zero, but nothing happens at all.

I first made it so that the max health is 3.

Script:

wait(1)
local P = game.Players.LocalPlayer
P.Character.Humanoid.MaxHealth = 3
P.Character.Humanoid.Health = 3

Next, I put three hearts and a local script into each of them. Each script makes the heart disappear when the health is at that number. But none of them work. I tried adding a while true loop, but that didn't work either.

Here is the local script I used that would remove every heart when the health reaches zero:

wait(1)
local P = game.Players.LocalPlayer

if P.Character.Humanoid.Health == 3 then
	script.Parent.Visible = true
end

if P.Character.Humanoid.Health == 2 then
	script.Parent.Visible = false
end

The other local scripts are similar, but they only remove the heart that they are in.

9 comments

0

did you try P.Character.Humanoid.Health.Changed:Connect(function()

0

It gives me an error saying "Players.CaptainAlien132.PlayerGui.Hearts.HeartC.LocalScript:4: attempt to index field 'Health' (a number value)"

0

Wouldn't your initial script constantly raise the players health back to 3? Shouldnt that be only on Connect not on a loop

0

How would it change the health? The first script doesn't loop meaning it happens once.

0

  oh im mistaken, I apologize.

0

It's okay

0

will u accept an answer for the question

0

If it works, then yes.

0

changed event is a property of instances, Health is a number value, use P.Character.Humanoid.Changed event, not P.Character.Humanoid.Health.Changed.