Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to know what a player's health is at all times? (Answered)

Asked by 4 years ago
Edited 4 years ago

I made a script, but it doesn't work. If any could help me it would be great

local Humanoid = game.Players.LocalPlayer.Character.Humanoid
local currentHealth = Humanoid.Health

Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
    print(currentHealth)
end)
0
Is there any error's in your developer console? isaacjh100 41 — 4y
0
Not that I can see ArvidSilverlock 50 — 4y

1 answer

Log in to vote
1
Answered by
NotedAPI 810 Moderation Voter
4 years ago

Hello, ArvidSilverlock!

One way to know a players health at all times is by using the HealthChanged event. This will automatically tell you their new health wether it goes up or down. The script below should help you with your problem. If you find any errors feel free to reply and let me know

HealthChanged is just like the normal Changed event but it's used for health. This event will fire everytime the LocalPlayers health has changed.

Insert a LocalScript into StarterCharacterScripts and put the following code:

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")

Humanoid.HealthChanged:Connect(function(NewHealth)
    print(NewHealth)
end)
0
Thank you! ArvidSilverlock 50 — 4y
0
Not a problem. Enjoy making your game! NotedAPI 810 — 4y
Ad

Answer this question