How to get player HP and display it in a frame?

Hello! i need help, i don’t know how to get the player HP and i need some help with that… could someone help me please!

local Hum = v.Character:FindFirstChild("Humanoid")

						if Hum and Hum.Health > 0 then --Checks if player is alive.
							Hum.Health = Hum.Health - 15 --Change "100" to the damage the player should take.
							wait(1)
						end
1 Like

Do you mean you want to have a text that shows their HP?

wait(3)
local textlabel = --define textlabel here

local player = game.Players.LocalPlayer

player.CharacterAdded:Wait()

local humanoid = player.Character:WaitForChild("Humanoid")

humanoid.Health.Changed:Connect(function()
       textlabel.Text = "Health: "..humanoid.Health
end)
3 Likes

I do believe that it is Humanoid.HealthChanged rather than Humanoid.Health.Changed

2 Likes

If you mean to use a frame as a custom health bar, you just set the size of the frame proportionately to the health

so parent this under a frame, and it will resize the frame based on the current health and the max health
(make sure that the anchorpoint of the frame is (0,0.5) before you put it where you want it on the screen

local sp = script.Parent
local OriginalSizeX = sp.Size.X.Scale
local OriginalSizeY = sp.Size.Y.Scale

game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local Humanoid = game.Players.LocalPlayer.Character.Humanoid

game.Players.LocalPlayer.Character.Humanoid.HealthChanged:Connect(function(Health)
	local MaxHealth = Humanoid.MaxHealth
	if Health >0 then
		local SizeOutputX = (OriginalSizeX*Health)/ MaxHealth
		sp.Size = UDim2.new(SizeOutputX, 0, OriginalSizeY, 0)
	end
end)
3 Likes

I’d way what you’re looking for is a health bar, look this:

or this

4 Likes

If you wanna do a text that show players health, i already did this in a script a week ago
[ Put this script in a local script inside of a TextLabel ] :

–>variables

local humanoid = game.Players.LocalPlayer.Character:WaitForChild(‘Humanoid’)

–>script

while wait() do

script.Parent.Text = humanoid.Health

end

4 Likes

Thanks you all guys! Tomorrow i’ll try all these ways to make a healthbar :smiley:

1 Like

You’re welcome! Good luck in your project.

1 Like

it works! thanks you a lot! :smiley:

1 Like

Im happy to have helped with your project, good luck.

2 Likes