Hello, I’m currently trying to make it so when the player dies and their Humanoids health reaches 0, a label image’s visibility is set to false making the image no longer to be seen, until their HP has gone back to 100.
You have to use the HealthChanged event that comews from the humanoid. So you’d have to do something like
Humanoid.HealthChanged:Connect(function(health)
if health <= 0 then
--Code
else
--Code
end
end)
Also your code to cahnge the visible wont work as you need PlayerGui, not StarterGui. If the localscript is in Startergui, then you go back through the hierachy till you reach StarterGui, or you could use `game.Players.LocalPlayer:WaitForChild(“PlayerGui”)
You should use WaitForChild() cause sometimes the Character doesn’t exactly load in time with the script
There is actually a way to check for a Player’s Health changing, and that’s the Humanoid.HealthChanged event
Humanoid.Health is a Float (Value), not a StringValue lol
“Health_Images” and “Heart_full” will result in errors, change those to ["Health_Images"] and ["Heart_full"] (I’m used to assuming every special symbol will result in an error, so mb ignore that one)
Also, you’re getting the StarterGui, not the PlayerGui
Try this and see if it fixes?
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Gui = Player:WaitForChild("PlayerGui")
Humanoid.HealthChanged:Connect(function()
if Humanoid.Health <= 0 then
Gui.Health["Health_Images"]["Heart_full"].Visible = false
elseif Humanoid.Health >= 1 then
Gui.Health["Health_Images"]["Heart_full"].Visible = true
end
end)
sorry for the late response. Yeah, unfortunately that didn’t work for me. Though I was able to use the information you and everyone else gave me to produce this.
There isn’t any issue in the console anymore, though for some reason this still isn’t working lol, sorry for bothering, but I’m new to scripting.
You’re only getting the currentHealth variable (Which is not being changed every time the health changes), not the actual health parameter the HealthChanged Event gives you, use that instead
humanoid.HealthChanged:Connect(function(ActualHealth)
if ActualHealth <= 0 then
Gui.Health.Full.Visible = false
elseif ActualHealth >= 1 then
Gui.Health.Full.Visible = true
end
end)
Also, don’t put else if separately, you just need elseif on its own