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

How do I fix my custom health bar?

local player = game.Players.LocalPlayer --Get Player

repeat wait() until player.Character --Wait for player

local Humanoid = Player.Character:WaitForChild("Humanoid") --Get the humanoid

Humanoid.HealthChanged:Connect(function(health) --Change the healthbar when the health changes
	script.Parent.Health.HealthBar.Size.X.Scale = Humanoid.Health*.85 --//healthbar scale size is .85 so I mutliply the health (100) by .85 to make it the propersize so I dont get numbers like .9 (90 health)
	script.Parent.Health.Health.Text = Humanoid.Health --Change the displayed number
end)

I don't know why this doesn't work. I've looked at tutorials online, and tried those, but those dont seem to work either. I want the health bar to close in on both sides so it looks more professionally done, but I don't know if I can do that anymore.

1 answer

local player = game.Players.LocalPlayer --Get Player

repeat wait() until player.Character

local Humanoid = Player.Character:WaitForChild("Humanoid") 

Humanoid.HealthChanged:Connect(function(health) 
    script.Parent.Health.HealthBar.Size= UDim2.new(Humanoid.Health / Humanoid.MaxHealth *.85, 0, script.Parent.Health.HealthBar.Size.Y.Scale, 0) 
    script.Parent.Health.Health.Text = Humanoid.Health
end)

Size.X and Size.Y is a read-only property. Also you should divide the max health. Btw sorry that i deleted ur comments but i just could not read.

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