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

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

The Code In StarterCharacterScript -

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

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

5 comments

0

i dont think im correct, but dont you have to make it Health Changed?

0

use a humanoid.HealthChanged event

0

i tried that

0

You did not specify what the problem is.

0

oh ye ill add that srry

1 answer

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:


local char = script.Parent
local human = char:FindFirstChild('Humanoid')

human.Changed:connect(function()
	print('test')
	local health = human.Health
	local maxhealth = human.MaxHealth
	char.Head.HealthBar.GreenBar.Size = UDim2.new(health/maxHealth,0,1,0)
end)

3 comments

0

If you get any errors then comment them plesae

0

already tried that and no errors the script just wont run or something

0

Ye no matter what i do i try loops functions events it never works

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