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

(Still Unanswered) How to fix this? i'm making custom overhead health GUI

Asked by 6 years ago
Edited 6 years ago

The Code In StarterCharacterScript -

1local char = script.Parent
2char.Changed:connect(function()
3    print("ads")
4    local hum = char.Humanoid
5    local health = hum.Health
6    local maxHealth = hum.MaxHealth
7    char.Head.HealthBar.GreenBar.Size = UDim2.new(health/maxHealth,0,1,0)
8end)

Also the Billboard GUI is in the characters head

Problem -

Whenever the humanoid takes damage the green bar wont scale to its health.

Also its a billboard GUI in the players head

0
i dont think im correct, but dont you have to make it Health Changed? Kurcha 33 — 6y
0
use a humanoid.HealthChanged event theking48989987 2147 — 6y
0
i tried that ComplexCrypt -5 — 6y
0
You did not specify what the problem is. wilsonsilva007 373 — 6y
0
oh ye ill add that srry ComplexCrypt -5 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

If I am correct, char is referencing the Player's model instead of the humanoid. If you want the healthbar to update when the player takes damage, then the function must fire when the humanoid changes (specifically the humanoid's health).

Try using this:

1local char = script.Parent
2local human = char:FindFirstChild('Humanoid')
3 
4human.Changed:connect(function()
5    print('test')
6    local health = human.Health
7    local maxhealth = human.MaxHealth
8    char.Head.HealthBar.GreenBar.Size = UDim2.new(health/maxHealth,0,1,0)
9end)
0
If you get any errors then comment them plesae Deadman7117 46 — 6y
0
already tried that and no errors the script just wont run or something ComplexCrypt -5 — 6y
0
Ye no matter what i do i try loops functions events it never works ComplexCrypt -5 — 6y
Ad

Answer this question