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

(Health bar gui) Not working?

Asked by 9 years ago

The goal of the script is to project the players help, onto the guis text, plain and simple, but it doesn't seem to work? any ideas?

while true do
    wait(0.1)
local plr = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent
local char = plr.Character
local human = char.Humanoid
local Health = human.Health
local par = script.Parent
local text = par.Text
text = Health
end

Thanks

1 answer

Log in to vote
0
Answered by 9 years ago

First of all, when it comes to this, I suggest you place this in a LocalScript.

Assuming you are going to do this, here's the code:

local plr = game.Players.LocalPlayer
local char = plr.Character
local human = char.Humanoid
local par = script.Parent
par.Text = math.floor(human.Health)

human.HealthChanged:connect(function(newhealth)
    par.Text = math.floor(newhealth)
end)

You don't need to use a "while true do" to check the player's health in real-time, you only need a function. Referencing a value only stores a copy of it, therefore editing the copy will not synchronize it to the value in the instance.

1
Thx, it helped but is there anyway to prevent any crazy numbers like 21.000121331 from appearing in the text ghosteffectz 115 — 9y
1
Yes, I've edited the code. HECKFURNIOUS 85 — 9y
Ad

Answer this question