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

[SOLVED BY COMMENT] Why is the IntValue not changing to the player's health?

I'm creating a health bar in which every time the player's health changes, the bar would go down relative to the player's current health. I have two values in StarterGui.HealthBar. One is called MaxHealth and the other is CurrentHealth.

Here is my script: (LocalScript)

repeat wait() until game.Players.LocalPlayer.Character
local humanoid = game.Players.LocalPlayer.Character:FindFirstChild('Humanoid')

local maxHealth = script.Parent.MaxHealth
local currentHealth = script.Parent.CurrentHealth


local backgroundFrame = script.Parent.Main.BackgroundHealth
local realFrame = backgroundFrame.Health

currentHealth.Changed:Connect(function()
	realFrame:TweenSize(UDim2.new(currentHealth / maxHealth,0,1,0),'In','Sine',.2)
end)

However, the value of CurrentHealth is not changing according to the humanoid's health.

Any help?

EDIT: Thanks to PixelRankYT for solving the problem. Apparently the problem was that I didn't use Humanoid.Changed. I never knew that! :OO

4 comments

1

You need to check if the humanoid changes. NOTE: That's how I seen people do health bars!

0

How would I do that?

0

humanoid.Changed:Connect(function()

0

Oh.

1 answer

humanoid.Changed:Connect(function() was actually the answer... I never knew that...

Thanks to PixelRankYT for answering!

(all credit goes to him, this answer is actually his)

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