I'm attempting to make a GUI that displays the amount of lives the player has. Each time they die they are supposed to lose a life. I placed into the Workspace a local script with the following code.
local player = game.Players.LocalPlayer G_lives = 3; if (player.health == 0) then G_lives = G_lives - 1 print(G_lives) end
I'm getting no output from this though, and I'm not exactly sure why. Could anyone explain the flaw in my code?
Player
object. You get it from the Humanoid
.local plr = game:GetService("Players").LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait() char.Humanoid.HealthChanged:Connect(function(newHealth) print("The new health of the humanoid is:", newHealth) end)
The health isnt in the player, its in the Character or the Character's humanoid. This means you have to go player.Character.Humanoid.Health or player.Character.Health
I changed my code to this:
local player = game:GetService("Players").LocalPlayer local char = player.Character or player.CharacterAdded:Wait() if (char.Humanoid.Health == 0) then G_lives = G_lives - 1 print(G_lives) end
I'm still not getting any output though. Did I misuse the information you guys gave me, or is it possibly because I have the localscript under workspace and it should be somewhere else?