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

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

Asked by
Kegani 31
6 years ago

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

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 JamiethegreatQ777 16 — 6y
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. JamiethegreatQ777 16 — 6y

1 answer

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago

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)
0
Thanks! Kegani 31 — 6y
Ad

Answer this question