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

(Health bar gui) Not working?

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

✓ Accepted answer

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.

2 comments

1

Thx, it helped but is there anyway to prevent any crazy numbers like 21.000121331 from appearing in the text

1

Yes, I've edited the code.

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