Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I get the "live" amount of health remaining?

Hello

I'm currently trying to get the amount of health remaining and put it in a TextLabel. However, I don't know how to make it like, "live". The current script I have doesn't update when I change my health. There is also a TextLabel I try to change the text color of whenever the health is below 50, 25 or even equal to 0.

if plr.Character.Humanoid.Health <= "50" then
	sta.healcolor.TextColor3 = BrickColor.new("245, 230, 15")
end
if plr.Character.Humanoid.Health <= "25" then
	sta.healcolor.TextColor3 = BrickColor.new("255, 95, 3")
end
if plr.Character.Humanoid.Health == "0" then
	sta.healcolor.TextColor3 = BrickColor.new("255, 0, 0")
	sta.healcolor.Text = "Dead"
end
sta.health.Text = plr.Character.Humanoid.Health

Please give me help for this. By the way, http://prntscr.com/iomkfu

2 comments

0

Start By Making A ScreenGui In StarterGui Then Make A Script With The Following Code And Make A Frame With A Frame Named "Health" Inside That Put A Frame Then A Frame Named Text With A TextLabel In That wait(0.5) local char = script.Parent.Parent.Parent.Character local hum = char.Humanoid hum.Changed:connect(function() script.Parent.Frame.Health.Frame.Size = UDim2.new(hum.Health / hum.MaxHealth

0

Copy and paste from wait :) hope this helped Also set the bacground colour and text colour in properties it will automaticly change :) Have A Good Day.

1 answer

✓ Accepted answer

In a LocalScript, you'll have to use RenderStepped or HealthChanged.

You can search them up on the Roblox wiki.

local player = game.Player.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char.Humanoid

hum.HealthChanged:Connect(function(health)
       sta.Health.Text = health
       if health <= 50 then
              stat.healcolor.TextColor3 = Color3.fromRGB(245,230,15)
       end
       if health <= 25 then
             stat.healcolor.TextColor3 = Color3.fromRGB(255,93,3)
       end
       if health == 0 then
             stat.healcolor.Text = 'Dead'
             stat.healcolor.TextColor3 = Color3.fromRGB(255,0,0)
       end
end)

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.