I made a healthbar for a zombie titan where the healthbar is in the form of a screengui.Hbar
but for some reason, the blood doesn’t update when the server :destroy zombies
(for example player damage zombie 50/100, then server :destroy all zombies because time runs out)
when a new round starts, the health of the screengui.Hbar starts from 100/100 again instead of 50/100
the stage of how its happening:
server clone the zombie to wspace
local zmb = ss[random]:Clone()
ss.Parent = workspace
.
hbar script, will retrieve health data from workspace.Zombie.Humanoid.Health
local Character = game.Workspace:WaitForChild("R6")
local hum = Character:WaitForChild("Humanoid") -- player humanoid
HpText.Text = string.format("Health: %s/%s", hum.Health, hum.MaxHealth) -- The hp TextLabel
etc...
so how do I get ,health updates to previous health?
local Character = game.Workspace:WaitForChild("R6")
local hum = Character:WaitForChild("Humanoid") -- player humanoid
HpText.Text = string.format("Health: %s/%s", hum.Health, hum.MaxHealth) -- The hp TextLabel
I don’t think you’re changing the health every time, that might be causing it, try using a while loop, like this:
local Character = game.Workspace:WaitForChild("R6")
local hum = Character:WaitForChild("Humanoid") -- player humanoid
while task.wait(1) do
HpText.Text = string.format("Health: %s/%s", hum.Health, hum.MaxHealth) -- The hp TextLabel
end
You wanna run that code everytime the health changes, do this with ‘PropertyChangedSignal()’.
local Character = game.Workspace:WaitForChild("R6")
local hum = Character:WaitForChild("Humanoid") -- player humanoid
function UpdateGui()
HpText.Text = string. Format("Health: %s/%s", hum.Health, hum.MaxHealth) -- The hp TextLabel
end
hum:GetPropertyChangedSignal('Health'):Connect(UpdateGui)