You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
To set back to 100 when you die
-
What is the issue? Include screenshots / videos if possible!
My health bar isnt working when you reset or die like its just 0
local Health = script.Parent.Health
local player = game.Players.LocalPlayer
local Char = player.Character
local Hum = Char:WaitForChild("Humanoid")
while wait() do
Health.Text = ""..math.floor(Hum.Health)
end
2 Likes
and no i dont want to resetonspawn enabled
I recommend using CharacterAdded:
game.Players.CharacterAdded:Connect(function()
Health.Text = Hum.MaxHealth
end)
Apologies if I did something incorrectly, I’m currently typing this on mobile
hmmm ok wonder why it took you so long to type that
bruh you don’t no apologies however im gonna thank you
where would i put that line exactly?
Above the wait() loop, also I don’t recommend using while wait() loop, you should check if Health value changes
it does but it doesnt change when i die
Hum:GetPropertyChangedSignal("Health"):Connect(function()
Health.Text = math.floor(Hum.Health)
end)
hold on line 8 is saying that CharacterAdded is not a valid of Players
local player = game.Players.LocalPlayer
local Char = player.Character
local Hum = Char:WaitForChild("Humanoid")
while wait() do
game.Players.CharacterAdded:Connect(function()
Health.Text = Hum.MaxHealth
end)
Hum:GetPropertyChangedSignal("Health"):Connect(function()
Health.Text = math.floor(Hum.Helath)
end)
end
local player = game.Players.LocalPlayer
local Char = player.Character
local Hum = Char:WaitForChild("Humanoid")
while wait() do
game.Players.LocalPlayer.CharacterAdded:Connect(function()
Health.Text = Hum.MaxHealth
end)
Hum:GetPropertyChangedSignal("Health"):Connect(function()
Health.Text = math.floor(Hum.Helath)
end)
end
bruh i found i a typo in my script right by end end)
that typo flooded my console bruh
you might want to change the 12 line to Helath to Health
You could write something like the below:
local HCConn = Humanoid.HealthChanged:Connect(function(CurrentHealth)
Health.Text = tostring(math.floor(Humanoid.Health))
end)
Humanoid.Died:Connect(function()
HCConn:Disconnect()
Health.Text = "0"
end)
why tho it works fine now? so whats the point?
It removes having to use a loop, instead using event-driven programming to present the data for the user. It also won’t bog up resources by having the events inside a while
loop, causing a memory leak.
ok I see what you mean thx so much man
1 Like