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

Help with non player Health Bar ?

Maybe I'm missing something obvious here? For some reason, "Humanoid.Health" isn't updating, and "Humanoid.HealthChanged" only fires when the Humanoid dies. The script is located withing the GUI I'm using (for healthbar) which is inside the Dummies head. Same script works fine for my player HP bar.

local Hum = script.Parent.Parent.Parent.Humanoid
local NameVal = script.Parent.NameLab
local HPVal = script.Parent.HealthBar.Back.HPLab
local Bar = script.Parent.HealthBar.Bar
HPVal.Text = Hum.Health .. "/" .. Hum.MaxHealth 
Hum.Changed:Connect(function()
    print(Hum.Health)
    wait(2)
end)
Hum.HealthChanged:Connect(function(health)
    HPVal.Text = Hum.Health .. "/" .. Hum.MaxHealth 
    Bar.Size = UDim2.new(Hum.Health/Hum.MaxHealth,0,2,0)
end)

The Hum.Health output never changes from 100, until the Humanoid dies.

5 comments

0

if the health of the humanoid is being changed through a LocalScript then that could be the problem

0

try using a normal script if your using a LocalScript

0

No!! This script doesn't can be a ServerScript! It's just possible to make a health bar with LocalScript (or ClientScript).

0

Honestly, a loop can update it. like so: while wait(1) do print(Hum.Health) end

0

Arsubia12 fixed my problem. It was because the thing I was testing with used a local script to damage.

1 answer

✓ Accepted answer

If you want make a health bar you must writte your script on a LocalScript (ClientScript). Place your script on a client storage, ex: StarterGui (or descendance).

local PlayerService = game:GetService('Players') -- Get the players service.

local Player = PlayerService.LocalPlayer -- This is just possible on a LocalScript.
local Character = Player.Character or Player.CharacterAdded:wait() -- In case the character model has already been created

local PlayerGui = Player:WaitForChild('PlayerGui') -- You can't found PlayerGui with the server, so you can't make this script on a ServerScript (Script)

local NameVal = PlayerGui[ name of you screengui ]
local HPVal = ...
local Bar = ... (it's just a links)

Character:WaitForChild('Humanoid'):GetPropertyChangedSignal('Health'):Connect(function()
	HPVal.Text = Hum.Health .. "/" .. Hum.MaxHealth
	Bar.Size = UDim2.new(Character.Humanoid.Health / Character.Humanoid.MaxHealth, 0, 2 ,0)
end)

EXEMPLE

local PlayerService = game:GetService('Players')

local Player = PlayerService.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()

local PlayerGui = Player:WaitForChild('PlayerGui')

local Bar = PlayerGui.ScreenGui.Frame.Frame (Link towards my bar ui)

Character:WaitForChild('Humanoid'):GetPropertyChangedSignal('Health'):Connect(function()
    Bar.Size = UDim2.new(Character.Humanoid.Health / Character.Humanoid.MaxHealth, 0, 1 ,0)
end)

Solved your question? Put in title [SOLVED] or accept a answer.

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